huangcm
2025-03-10 313d899ea76a728046c194ded35c2d20909cb707
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * drivers/cpufreq/autohotplug.h
 *
 * Copyright (C) 2016-2020 Allwinnertech.
 * East Yang <yangdong@allwinnertech.com>
 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
 
#ifndef __AUTOHOTPLUG__
#define __AUTOHOTPLUG__
 
#define INVALID_LOAD    0xffffffff
#define INVALID_CPU     0xffffffff
 
#define STABLE_DOWN           0
#define STABLE_UP             1
#define STABLE_BOOST          2
#define STABLE_LAST_BIG       3
 
#if defined(CONFIG_SCHED_HMP)
   #define AUTOHOTPLUG_SUNXI_SYSFS_MAX (7)
#elif defined(CONFIG_SCHED_SMP_DCMP)
   #define AUTOHOTPLUG_SUNXI_SYSFS_MAX (2)
#else
   #define AUTOHOTPLUG_SUNXI_SYSFS_MAX (0)
#endif
 
#ifdef CONFIG_CPU_AUTOHOTPLUG_STATS
   #define AUTOHOTPLUG_STATS_SYSFS_MAX (3 * (CONFIG_NR_CPUS))
#else
   #define AUTOHOTPLUG_STATS_SYSFS_MAX (0)
#endif
 
#define HOTPLUG_DATA_SYSFS_MAX (9 + AUTOHOTPLUG_SUNXI_SYSFS_MAX + \
                   AUTOHOTPLUG_STATS_SYSFS_MAX)
 
struct autohotplug_loadinfo {
   unsigned int  cpu_load[CONFIG_NR_CPUS];
   unsigned int  cpu_load_relative[CONFIG_NR_CPUS];
   unsigned int  max_load;
   unsigned int  min_load;
   unsigned int  max_cpu;
   unsigned int  min_cpu;
   unsigned int  big_min_load;
};
 
struct autohotplug_governor_loadinfo {
   struct timer_list cpu_timer;
   struct autohotplug_loadinfo load;
};
 
struct autohotplug_cpuinfo {
   spinlock_t load_lock; /* protects the next 4 fields */
   u64 time_in_idle;
   u64 time_in_idle_timestamp;
};
 
struct autohotplug_global_attr {
   struct attribute attr;
   ssize_t (*show)(struct kobject *kobj,
           struct attribute *attr, char *buf);
   ssize_t (*store)(struct kobject *a, struct attribute *b,
           const char *c, size_t count);
   unsigned int *value;
   unsigned int (*to_sysfs)(unsigned int, unsigned int *);
   unsigned int (*from_sysfs)(unsigned int, unsigned int *);
};
 
struct autohotplug_data_struct {
   struct attribute_group attr_group;
   struct attribute *attributes[HOTPLUG_DATA_SYSFS_MAX + 1];
   struct autohotplug_global_attr attr[HOTPLUG_DATA_SYSFS_MAX];
};
 
struct autohotplug_governor {
   void (*init_attr)(void);
   int  (*get_fast_and_slow_cpus)(struct cpumask *hmp_fast_cpu_mask,
           struct cpumask *hmp_slow_cpu_mask);
   int  (*try_up)(struct autohotplug_loadinfo *load);
   int  (*try_down)(struct autohotplug_loadinfo *load);
   void (*try_freq_limit)(void);
};
 
extern unsigned int is_cpu_big(int cpu);
extern unsigned int is_cpu_little(int cpu);
extern int do_cpu_down(unsigned int cpu);
extern int try_up_little(void);
extern int try_up_big(void);
 
extern void autohotplug_attr_add(const char *name,
       unsigned int *value, umode_t mode,
       unsigned int (*to_sysfs)(unsigned int, unsigned int *),
       unsigned int (*from_sysfs)(unsigned int, unsigned int*));
extern int get_cpus_under(struct autohotplug_loadinfo *load,
               unsigned char level, unsigned int *first);
extern int get_bigs_above(struct autohotplug_loadinfo *load,
               unsigned char level, unsigned int *first);
extern int get_littles_under(struct autohotplug_loadinfo *load,
               unsigned char level, unsigned int *first);
extern int get_bigs_under(struct autohotplug_loadinfo *load,
               unsigned char level, unsigned int *first);
extern int get_cpus_stable_under(struct autohotplug_loadinfo *load,
       unsigned char level, unsigned int *first, int is_up);
extern int get_cpus_online(struct autohotplug_loadinfo *load,
               int *little, int *big);
 
extern struct autohotplug_governor autohotplug_smart;
 
extern unsigned int  load_try_down;
extern unsigned int  load_try_up;
extern unsigned long cpu_up_lasttime;
extern unsigned int  load_up_stable_us;
extern unsigned int  load_down_stable_us;
#ifdef CONFIG_SCHED_HMP
extern void __init arch_get_fast_and_slow_cpus(struct cpumask *fast,
                       struct cpumask *slow);
#endif
 
#endif  /* #ifndef __AUTOHOTPLUG__ */