From 98f56816fcb5c97e0afd21a6e242bb72d5b7a551 Mon Sep 17 00:00:00 2001 From: Christopher Kenna Date: Fri, 22 Oct 2010 17:26:38 -0400 Subject: Litmus core: per-plugin proc directories Change the Litmus proc layout so that loaded plugins are visible in /proc/litmus/plugins/loaded and add Litmus functions make_plugin_proc_dir() and remove_plugin_proc_dir() to add per-plugin proc directories. --- include/litmus/litmus.h | 16 +++++++++++++ litmus/litmus.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/include/litmus/litmus.h b/include/litmus/litmus.h index 5d20276e44f4..ccb6b137952b 100644 --- a/include/litmus/litmus.h +++ b/include/litmus/litmus.h @@ -9,6 +9,9 @@ #include #include +#include +#include + #ifdef CONFIG_RELEASE_MASTER extern atomic_t release_master_cpu; #endif @@ -62,6 +65,19 @@ void exit_litmus(struct task_struct *dead_tsk); long litmus_admit_task(struct task_struct *tsk); void litmus_exit_task(struct task_struct *tsk); +/* + * On success, returns 0 and sets the pointer to the location of the new + * proc dir entry, otherwise returns an error code and sets pde to NULL. + */ +long make_plugin_proc_dir(struct sched_plugin* plugin, + struct proc_dir_entry** pde); + +/* + * Plugins should deallocate all child proc directory entries before + * calling this, to avoid memory leaks. + */ +void remove_plugin_proc_dir(struct sched_plugin* plugin); + #define is_realtime(t) ((t)->policy == SCHED_LITMUS) #define rt_transition_pending(t) \ ((t)->rt_param.transition_pending) diff --git a/litmus/litmus.c b/litmus/litmus.c index e854ba317762..3b73b39ffbbf 100644 --- a/litmus/litmus.c +++ b/litmus/litmus.c @@ -8,12 +8,10 @@ #include #include -#include #include #include #include -#include #include @@ -687,6 +685,7 @@ static int proc_write_release_master(struct file *file, static struct proc_dir_entry *litmus_dir = NULL, *curr_file = NULL, *stat_file = NULL, + *plugs_dir = NULL, *plugs_file = NULL, #ifdef CONFIG_RELEASE_MASTER *release_master_file = NULL, @@ -736,7 +735,14 @@ static int __init init_litmus_proc(void) stat_file = create_proc_read_entry("stats", 0444, litmus_dir, proc_read_stats, NULL); - plugs_file = create_proc_read_entry("plugins", 0444, litmus_dir, + plugs_dir = proc_mkdir("plugins", litmus_dir); + if (!plugs_dir){ + printk(KERN_ERR "Could not allocate plugins directory " + "procfs entry.\n"); + return -ENOMEM; + } + + plugs_file = create_proc_read_entry("loaded", 0444, plugs_dir, proc_read_plugins, NULL); return 0; @@ -745,6 +751,8 @@ static int __init init_litmus_proc(void) static void exit_litmus_proc(void) { if (plugs_file) + remove_proc_entry("loaded", plugs_dir); + if (plugs_dir) remove_proc_entry("plugins", litmus_dir); if (stat_file) remove_proc_entry("stats", litmus_dir); @@ -760,6 +768,54 @@ static void exit_litmus_proc(void) remove_proc_entry("litmus", NULL); } +long make_plugin_proc_dir(struct sched_plugin* plugin, + struct proc_dir_entry** pde_in) +{ + struct proc_dir_entry *pde_new = NULL; + long rv; + + if (!plugin || !plugin->plugin_name){ + printk(KERN_ERR "Invalid plugin struct passed to %s.\n", + __func__); + rv = -EINVAL; + goto out_no_pde; + } + + if (!plugs_dir){ + printk(KERN_ERR "Could not make plugin sub-directory, because " + "/proc/litmus/plugins does not exist.\n"); + rv = -ENOENT; + goto out_no_pde; + } + + pde_new = proc_mkdir(plugin->plugin_name, plugs_dir); + if (!pde_new){ + printk(KERN_ERR "Could not make plugin sub-directory: " + "out of memory?.\n"); + rv = -ENOMEM; + goto out_no_pde; + } + + rv = 0; + *pde_in = pde_new; + goto out_ok; + +out_no_pde: + *pde_in = NULL; +out_ok: + return rv; +} + +void remove_plugin_proc_dir(struct sched_plugin* plugin) +{ + if (!plugin || !plugin->plugin_name){ + printk(KERN_ERR "Invalid plugin struct passed to %s.\n", + __func__); + return; + } + remove_proc_entry(plugin->plugin_name, plugs_dir); +} + extern struct sched_plugin linux_sched_plugin; static int __init _init_litmus(void) -- cgit v1.2.2