2121#include <linux/suspend.h>
2222#include <linux/export.h>
2323#include <linux/cpu.h>
24+ #include <linux/debugfs.h>
2425
2526#include "power.h"
2627
@@ -210,6 +211,18 @@ static void genpd_sd_counter_inc(struct generic_pm_domain *genpd)
210211}
211212
212213#ifdef CONFIG_DEBUG_FS
214+ static struct dentry * genpd_debugfs_dir ;
215+
216+ static void genpd_debug_add (struct generic_pm_domain * genpd );
217+
218+ static void genpd_debug_remove (struct generic_pm_domain * genpd )
219+ {
220+ struct dentry * d ;
221+
222+ d = debugfs_lookup (genpd -> name , genpd_debugfs_dir );
223+ debugfs_remove (d );
224+ }
225+
213226static void genpd_update_accounting (struct generic_pm_domain * genpd )
214227{
215228 ktime_t delta , now ;
@@ -234,6 +247,8 @@ static void genpd_update_accounting(struct generic_pm_domain *genpd)
234247 genpd -> accounting_time = now ;
235248}
236249#else
250+ static inline void genpd_debug_add (struct generic_pm_domain * genpd ) {}
251+ static inline void genpd_debug_remove (struct generic_pm_domain * genpd ) {}
237252static inline void genpd_update_accounting (struct generic_pm_domain * genpd ) {}
238253#endif
239254
@@ -1954,6 +1969,7 @@ int pm_genpd_init(struct generic_pm_domain *genpd,
19541969
19551970 mutex_lock (& gpd_list_lock );
19561971 list_add (& genpd -> gpd_list_node , & gpd_list );
1972+ genpd_debug_add (genpd );
19571973 mutex_unlock (& gpd_list_lock );
19581974
19591975 return 0 ;
@@ -1987,6 +2003,7 @@ static int genpd_remove(struct generic_pm_domain *genpd)
19872003 kfree (link );
19882004 }
19892005
2006+ genpd_debug_remove (genpd );
19902007 list_del (& genpd -> gpd_list_node );
19912008 genpd_unlock (genpd );
19922009 cancel_work_sync (& genpd -> power_off_work );
@@ -2893,14 +2910,6 @@ core_initcall(genpd_bus_init);
28932910/*** debugfs support ***/
28942911
28952912#ifdef CONFIG_DEBUG_FS
2896- #include <linux/pm.h>
2897- #include <linux/device.h>
2898- #include <linux/debugfs.h>
2899- #include <linux/seq_file.h>
2900- #include <linux/init.h>
2901- #include <linux/kobject.h>
2902- static struct dentry * genpd_debugfs_dir ;
2903-
29042913/*
29052914 * TODO: This function is a slightly modified version of rtpm_status_show
29062915 * from sysfs.c, so generalize it.
@@ -3177,35 +3186,43 @@ DEFINE_SHOW_ATTRIBUTE(total_idle_time);
31773186DEFINE_SHOW_ATTRIBUTE (devices );
31783187DEFINE_SHOW_ATTRIBUTE (perf_state );
31793188
3180- static int __init genpd_debug_init ( void )
3189+ static void genpd_debug_add ( struct generic_pm_domain * genpd )
31813190{
31823191 struct dentry * d ;
3192+
3193+ if (!genpd_debugfs_dir )
3194+ return ;
3195+
3196+ d = debugfs_create_dir (genpd -> name , genpd_debugfs_dir );
3197+
3198+ debugfs_create_file ("current_state" , 0444 ,
3199+ d , genpd , & status_fops );
3200+ debugfs_create_file ("sub_domains" , 0444 ,
3201+ d , genpd , & sub_domains_fops );
3202+ debugfs_create_file ("idle_states" , 0444 ,
3203+ d , genpd , & idle_states_fops );
3204+ debugfs_create_file ("active_time" , 0444 ,
3205+ d , genpd , & active_time_fops );
3206+ debugfs_create_file ("total_idle_time" , 0444 ,
3207+ d , genpd , & total_idle_time_fops );
3208+ debugfs_create_file ("devices" , 0444 ,
3209+ d , genpd , & devices_fops );
3210+ if (genpd -> set_performance_state )
3211+ debugfs_create_file ("perf_state" , 0444 ,
3212+ d , genpd , & perf_state_fops );
3213+ }
3214+
3215+ static int __init genpd_debug_init (void )
3216+ {
31833217 struct generic_pm_domain * genpd ;
31843218
31853219 genpd_debugfs_dir = debugfs_create_dir ("pm_genpd" , NULL );
31863220
31873221 debugfs_create_file ("pm_genpd_summary" , S_IRUGO , genpd_debugfs_dir ,
31883222 NULL , & summary_fops );
31893223
3190- list_for_each_entry (genpd , & gpd_list , gpd_list_node ) {
3191- d = debugfs_create_dir (genpd -> name , genpd_debugfs_dir );
3192-
3193- debugfs_create_file ("current_state" , 0444 ,
3194- d , genpd , & status_fops );
3195- debugfs_create_file ("sub_domains" , 0444 ,
3196- d , genpd , & sub_domains_fops );
3197- debugfs_create_file ("idle_states" , 0444 ,
3198- d , genpd , & idle_states_fops );
3199- debugfs_create_file ("active_time" , 0444 ,
3200- d , genpd , & active_time_fops );
3201- debugfs_create_file ("total_idle_time" , 0444 ,
3202- d , genpd , & total_idle_time_fops );
3203- debugfs_create_file ("devices" , 0444 ,
3204- d , genpd , & devices_fops );
3205- if (genpd -> set_performance_state )
3206- debugfs_create_file ("perf_state" , 0444 ,
3207- d , genpd , & perf_state_fops );
3208- }
3224+ list_for_each_entry (genpd , & gpd_list , gpd_list_node )
3225+ genpd_debug_add (genpd );
32093226
32103227 return 0 ;
32113228}
0 commit comments