@@ -43,9 +43,10 @@ static DEFINE_MUTEX(gov_dbs_data_mutex);
43
43
* This must be called with dbs_data->mutex held, otherwise traversing
44
44
* policy_dbs_list isn't safe.
45
45
*/
46
- ssize_t store_sampling_rate (struct dbs_data * dbs_data , const char * buf ,
46
+ ssize_t store_sampling_rate (struct gov_attr_set * attr_set , const char * buf ,
47
47
size_t count )
48
48
{
49
+ struct dbs_data * dbs_data = to_dbs_data (attr_set );
49
50
struct policy_dbs_info * policy_dbs ;
50
51
unsigned int rate ;
51
52
int ret ;
@@ -59,7 +60,7 @@ ssize_t store_sampling_rate(struct dbs_data *dbs_data, const char *buf,
59
60
* We are operating under dbs_data->mutex and so the list and its
60
61
* entries can't be freed concurrently.
61
62
*/
62
- list_for_each_entry (policy_dbs , & dbs_data -> policy_dbs_list , list ) {
63
+ list_for_each_entry (policy_dbs , & attr_set -> policy_list , list ) {
63
64
mutex_lock (& policy_dbs -> timer_mutex );
64
65
/*
65
66
* On 32-bit architectures this may race with the
@@ -96,7 +97,7 @@ void gov_update_cpu_data(struct dbs_data *dbs_data)
96
97
{
97
98
struct policy_dbs_info * policy_dbs ;
98
99
99
- list_for_each_entry (policy_dbs , & dbs_data -> policy_dbs_list , list ) {
100
+ list_for_each_entry (policy_dbs , & dbs_data -> attr_set . policy_list , list ) {
100
101
unsigned int j ;
101
102
102
103
for_each_cpu (j , policy_dbs -> policy -> cpus ) {
@@ -111,9 +112,9 @@ void gov_update_cpu_data(struct dbs_data *dbs_data)
111
112
}
112
113
EXPORT_SYMBOL_GPL (gov_update_cpu_data );
113
114
114
- static inline struct dbs_data * to_dbs_data (struct kobject * kobj )
115
+ static inline struct gov_attr_set * to_gov_attr_set (struct kobject * kobj )
115
116
{
116
- return container_of (kobj , struct dbs_data , kobj );
117
+ return container_of (kobj , struct gov_attr_set , kobj );
117
118
}
118
119
119
120
static inline struct governor_attr * to_gov_attr (struct attribute * attr )
@@ -124,25 +125,24 @@ static inline struct governor_attr *to_gov_attr(struct attribute *attr)
124
125
static ssize_t governor_show (struct kobject * kobj , struct attribute * attr ,
125
126
char * buf )
126
127
{
127
- struct dbs_data * dbs_data = to_dbs_data (kobj );
128
128
struct governor_attr * gattr = to_gov_attr (attr );
129
129
130
- return gattr -> show (dbs_data , buf );
130
+ return gattr -> show (to_gov_attr_set ( kobj ) , buf );
131
131
}
132
132
133
133
static ssize_t governor_store (struct kobject * kobj , struct attribute * attr ,
134
134
const char * buf , size_t count )
135
135
{
136
- struct dbs_data * dbs_data = to_dbs_data (kobj );
136
+ struct gov_attr_set * attr_set = to_gov_attr_set (kobj );
137
137
struct governor_attr * gattr = to_gov_attr (attr );
138
138
int ret = - EBUSY ;
139
139
140
- mutex_lock (& dbs_data -> mutex );
140
+ mutex_lock (& attr_set -> update_lock );
141
141
142
- if (dbs_data -> usage_count )
143
- ret = gattr -> store (dbs_data , buf , count );
142
+ if (attr_set -> usage_count )
143
+ ret = gattr -> store (attr_set , buf , count );
144
144
145
- mutex_unlock (& dbs_data -> mutex );
145
+ mutex_unlock (& attr_set -> update_lock );
146
146
147
147
return ret ;
148
148
}
@@ -425,6 +425,41 @@ static void free_policy_dbs_info(struct policy_dbs_info *policy_dbs,
425
425
gov -> free (policy_dbs );
426
426
}
427
427
428
+ static void gov_attr_set_init (struct gov_attr_set * attr_set ,
429
+ struct list_head * list_node )
430
+ {
431
+ INIT_LIST_HEAD (& attr_set -> policy_list );
432
+ mutex_init (& attr_set -> update_lock );
433
+ attr_set -> usage_count = 1 ;
434
+ list_add (list_node , & attr_set -> policy_list );
435
+ }
436
+
437
+ static void gov_attr_set_get (struct gov_attr_set * attr_set ,
438
+ struct list_head * list_node )
439
+ {
440
+ mutex_lock (& attr_set -> update_lock );
441
+ attr_set -> usage_count ++ ;
442
+ list_add (list_node , & attr_set -> policy_list );
443
+ mutex_unlock (& attr_set -> update_lock );
444
+ }
445
+
446
+ static unsigned int gov_attr_set_put (struct gov_attr_set * attr_set ,
447
+ struct list_head * list_node )
448
+ {
449
+ unsigned int count ;
450
+
451
+ mutex_lock (& attr_set -> update_lock );
452
+ list_del (list_node );
453
+ count = -- attr_set -> usage_count ;
454
+ mutex_unlock (& attr_set -> update_lock );
455
+ if (count )
456
+ return count ;
457
+
458
+ kobject_put (& attr_set -> kobj );
459
+ mutex_destroy (& attr_set -> update_lock );
460
+ return 0 ;
461
+ }
462
+
428
463
static int cpufreq_governor_init (struct cpufreq_policy * policy )
429
464
{
430
465
struct dbs_governor * gov = dbs_governor_of (policy );
@@ -453,10 +488,7 @@ static int cpufreq_governor_init(struct cpufreq_policy *policy)
453
488
policy_dbs -> dbs_data = dbs_data ;
454
489
policy -> governor_data = policy_dbs ;
455
490
456
- mutex_lock (& dbs_data -> mutex );
457
- dbs_data -> usage_count ++ ;
458
- list_add (& policy_dbs -> list , & dbs_data -> policy_dbs_list );
459
- mutex_unlock (& dbs_data -> mutex );
491
+ gov_attr_set_get (& dbs_data -> attr_set , & policy_dbs -> list );
460
492
goto out ;
461
493
}
462
494
@@ -466,8 +498,7 @@ static int cpufreq_governor_init(struct cpufreq_policy *policy)
466
498
goto free_policy_dbs_info ;
467
499
}
468
500
469
- INIT_LIST_HEAD (& dbs_data -> policy_dbs_list );
470
- mutex_init (& dbs_data -> mutex );
501
+ gov_attr_set_init (& dbs_data -> attr_set , & policy_dbs -> list );
471
502
472
503
ret = gov -> init (dbs_data , !policy -> governor -> initialized );
473
504
if (ret )
@@ -487,14 +518,11 @@ static int cpufreq_governor_init(struct cpufreq_policy *policy)
487
518
if (!have_governor_per_policy ())
488
519
gov -> gdbs_data = dbs_data ;
489
520
490
- policy -> governor_data = policy_dbs ;
491
-
492
521
policy_dbs -> dbs_data = dbs_data ;
493
- dbs_data -> usage_count = 1 ;
494
- list_add (& policy_dbs -> list , & dbs_data -> policy_dbs_list );
522
+ policy -> governor_data = policy_dbs ;
495
523
496
524
gov -> kobj_type .sysfs_ops = & governor_sysfs_ops ;
497
- ret = kobject_init_and_add (& dbs_data -> kobj , & gov -> kobj_type ,
525
+ ret = kobject_init_and_add (& dbs_data -> attr_set . kobj , & gov -> kobj_type ,
498
526
get_governor_parent_kobj (policy ),
499
527
"%s" , gov -> gov .name );
500
528
if (!ret )
@@ -523,29 +551,21 @@ static int cpufreq_governor_exit(struct cpufreq_policy *policy)
523
551
struct dbs_governor * gov = dbs_governor_of (policy );
524
552
struct policy_dbs_info * policy_dbs = policy -> governor_data ;
525
553
struct dbs_data * dbs_data = policy_dbs -> dbs_data ;
526
- int count ;
554
+ unsigned int count ;
527
555
528
556
/* Protect gov->gdbs_data against concurrent updates. */
529
557
mutex_lock (& gov_dbs_data_mutex );
530
558
531
- mutex_lock (& dbs_data -> mutex );
532
- list_del (& policy_dbs -> list );
533
- count = -- dbs_data -> usage_count ;
534
- mutex_unlock (& dbs_data -> mutex );
559
+ count = gov_attr_set_put (& dbs_data -> attr_set , & policy_dbs -> list );
535
560
536
- if (!count ) {
537
- kobject_put (& dbs_data -> kobj );
538
-
539
- policy -> governor_data = NULL ;
561
+ policy -> governor_data = NULL ;
540
562
563
+ if (!count ) {
541
564
if (!have_governor_per_policy ())
542
565
gov -> gdbs_data = NULL ;
543
566
544
567
gov -> exit (dbs_data , policy -> governor -> initialized == 1 );
545
- mutex_destroy (& dbs_data -> mutex );
546
568
kfree (dbs_data );
547
- } else {
548
- policy -> governor_data = NULL ;
549
569
}
550
570
551
571
free_policy_dbs_info (policy_dbs , gov );
0 commit comments