privatize various functions in sched.h
Subsystems (3)
This removes a bunch of inlines used only in isolated places from sched.h sched.h has too bad of a reputation as a "garbage can" header, so this aims to trim down the noise by taking functions that are private, making them private, and removing them from sched.h
There are some other rarely used macros and inlines that could also very well stand to simply be open-coded at the two or three callsites.
(1) task_cpu() / set_task_cpu()
used only by sched.c and proc_pid_stat(), so privatize to sched.c and open-code task->thread_info->cpu in proc_pid_stat(), the sole user of task_cpu() outside sched.h
(2) has_pending_signals() is used only in signal.c
privatize it
(3) eldest_child(), youngest_child(), elder_sibling(), younger_sibling() used only in sched.c, except for youngest_child(), which is completely unused
privatize them and remove youngest_child() completely
fs/proc/array.c | 2 - include/linux/sched.h | 82 -------------------------------------------------- kernel/sched.c | 32 +++++++++++++++++++ kernel/signal.c | 30 ++++++++++++++++++ 4 files changed, 63 insertions(+), 83 deletions(-)
fs/proc/array.c +1 -1
@@ -389,7 +389,7 @@ int proc_pid_stat(struct task_struct *ta task->nswap, task->cnswap, task->exit_signal, -task_cpu (task), + task->thread_info->cpu, task->rt_priority, task->policy);if (mm)
include/linux/sched.h +0 -82
100 lines not on this page · raw message
kernel/sched.c +32 -0
@@ -162,6 +162,20 @@ struct runqueue { static struct runqueue runqueues[NR_CPUS] __cacheline_aligned; +/* +* Wrappers for p->thread_info->cpu access. No-op on UP. +*/ +#ifdef CONFIG_SMP +#define task_cpu (task) ({(task)->thread_info->cpu; }) +static inline void set_task_cpu (task_t *task,int cpu) +{ + task->thread_info->cpu = cpu; +} +#else +#define task_cpu (task) 0 +#define set_task_cpu (task) do { } while (0) +#endif +#define cpu_rq (cpu) (runqueues + (cpu))#define this_rq () cpu_rq(smp_processor_id())#define task_rq (p) cpu_rq(task_cpu(p))
@@ -1844,6 +1858,24 @@ out_unlock:return retval; } +static inline struct task_struct *eldest_child (struct task_struct *p) +{ +if (list_empty (&p->children))return NULL ; + return list_entry(p->children.next,struct task_struct,sibling); +} + +static inline struct task_struct *older_sibling (struct task_struct *p) +{ +if (p->sibling.prev==&p->parent->children)return NULL ; + return list_entry(p->sibling.prev,struct task_struct,sibling); +} + +static inline struct task_struct *younger_sibling (struct task_struct *p) +{ +if (p->sibling.next==&p->parent->children)return NULL ; + return list_entry(p->sibling.next,struct task_struct,sibling); +} +static void show_task (task_t * p) {unsigned long free =0 ;
kernel/signal.c +30 -0
@@ -160,6 +160,36 @@ int max_queued_signals = 1024;static int __send_sig_info (int sig,struct siginfo *info,struct task_struct *p); +/* +* Re-calculate pending state from the set of locally pending +* signals, globally pending signals, and blocked signals. +*/ +static inline int has_pending_signals (sigset_t *signal,sigset_t *blocked) +{ +unsigned long ready; +long i; + +switch (_NSIG_WORDS) { +default : +for (i = _NSIG_WORDS, ready =0 ; --i >=0 ;) + ready |= signal->sig[i] &~ blocked->sig[i]; +break ; + +case 4 : ready = signal->sig[3 ] &~ blocked->sig[3 ]; + ready |= signal->sig[2 ] &~ blocked->sig[2 ]; + ready |= signal->sig[1 ] &~ blocked->sig[1 ]; + ready |= signal->sig[0 ] &~ blocked->sig[0 ]; +break ; + +case 2 : ready = signal->sig[1 ] &~ blocked->sig[1 ]; + ready |= signal->sig[0 ] &~ blocked->sig[0 ]; +break ; + +case 1 : ready = signal->sig[0 ] &~ blocked->sig[0 ]; + } +return ready !=0 ; +} +#define PENDING (p,b) has_pending_signals(&(p)->signal, (b))void recalc_sigpending_tsk (struct task_struct *t)
Quoted 1 line · William Lee Irwin III
This removes a bunch of inlines used only in isolated places from
sched.h
Hmm, while I'm at it, this applies atop the previous patch:
This removes d_path() from sched.h and uninlines it. No idea why it was in sched.h in the first place (or why something this large is inlined).
fs/dcache.c | 19 +++++++++++++++++++ include/linux/dcache.h | 1 + include/linux/sched.h | 20 -------------------- kernel/ksyms.c | 1 + 4 files changed, 21 insertions(+), 20 deletions(-)
fs/dcache.c +19 -0
@@ -1191,6 +1191,25 @@ global_root:return retval; } +/* write full pathname into buffer and return start of pathname */ +char *d_path (struct dentry *dentry,struct vfsmount *vfsmnt, +char *buf,int buflen) +{ +char *res; +struct vfsmount *rootmnt; +struct dentry *root; +read_lock (¤t->fs->lock); + rootmnt =mntget (current->fs->rootmnt); + root =dget (current->fs->root); +read_unlock (¤t->fs->lock); +spin_lock (&dcache_lock); + res =__d_path (dentry, vfsmnt, root, rootmnt, buf, buflen); +spin_unlock (&dcache_lock); +dput (root); +mntput (rootmnt); +return res; +} +/* * NOTE! The user-level library version returns a * character pointer. The kernel system call just
include/linux/dcache.h +1 -0
@@ -240,6 +240,7 @@ extern int d_validate(struct dentry *, sextern char *__d_path (struct dentry *,struct vfsmount *,struct dentry *,struct vfsmount *,char *,int ); +extern char *d_path (struct dentry *,struct vfsmount *,char *,int );/* Allocation counts.. */
include/linux/sched.h +0 -20
@@ -794,26 +794,6 @@ static inline void task_unlock(struct ta {spin_unlock (&p->alloc_lock); } - -/* write full pathname into buffer and return start of pathname */ -static inline char *d_path (struct dentry *dentry,struct vfsmount *vfsmnt, -char *buf,int buflen) -{ -char *res; -struct vfsmount *rootmnt; -struct dentry *root; -read_lock (¤t->fs->lock); - rootmnt =mntget (current->fs->rootmnt); - root =dget (current->fs->root); -read_unlock (¤t->fs->lock); -spin_lock (&dcache_lock); - res =__d_path (dentry, vfsmnt, root, rootmnt, buf, buflen); -spin_unlock (&dcache_lock); -dput (root); -mntput (rootmnt); -return res; -} -/** * get_task_mm - acquire a reference to the task's mm
kernel/ksyms.c +1 -0
@@ -166,6 +166,7 @@ EXPORT_SYMBOL(d_alloc);EXPORT_SYMBOL (d_alloc_anon);EXPORT_SYMBOL (d_splice_alias);EXPORT_SYMBOL (d_lookup); +EXPORT_SYMBOL (d_path);EXPORT_SYMBOL (__d_path);EXPORT_SYMBOL (mark_buffer_dirty);EXPORT_SYMBOL (end_buffer_io_sync);
Quoted 1 line · William Lee Irwin III
(1)
task_cpu()/set_task_cpu()
As pointed out by [email protected], set_task_cpu() needs a cpu argument for the non-SMP case:
This removes a bunch of inlines used only in isolated places from sched.h sched.h has too bad of a reputation as a "garbage can" header, so this aims to trim down the noise by taking functions that are private, making them private, and removing them from sched.h
(1) task_cpu() / set_task_cpu()
used only by sched.c and proc_pid_stat(), so privatize to sched.c and open-code task->thread_info->cpu in proc_pid_stat()
(2) has_pending_signals() is used only in signal.c
privatize it
(3) eldest_child(), youngest_child(), elder_sibling(), younger_sibling() used only in sched.c, except for youngest_child(), which is completely unused
privatize them
fs/proc/array.c | 2 - include/linux/sched.h | 82 -------------------------------------------------- kernel/sched.c | 32 +++++++++++++++++++ kernel/signal.c | 30 ++++++++++++++++++ 4 files changed, 63 insertions(+), 83 deletions(-)
fs/proc/array.c +1 -1
@@ -389,7 +389,7 @@ int proc_pid_stat(struct task_struct *ta task->nswap, task->cnswap, task->exit_signal, -task_cpu (task), + task->thread_info->cpu, task->rt_priority, task->policy);if (mm)
include/linux/sched.h +0 -82
100 lines not on this page · raw message
kernel/sched.c +32 -0
@@ -162,6 +162,20 @@ struct runqueue { static struct runqueue runqueues[NR_CPUS] __cacheline_aligned; +/* +* Wrappers for p->thread_info->cpu access. No-op on UP. +*/ +#ifdef CONFIG_SMP +#define task_cpu (task) ({(task)->thread_info->cpu; }) +static inline void set_task_cpu (task_t *task,int cpu) +{ + task->thread_info->cpu = cpu; +} +#else +#define task_cpu (task) 0 +#define set_task_cpu (task, cpu) do { } while (0) +#endif +#define cpu_rq (cpu) (runqueues + (cpu))#define this_rq () cpu_rq(smp_processor_id())#define task_rq (p) cpu_rq(task_cpu(p))
@@ -1844,6 +1858,24 @@ out_unlock:return retval; } +static inline struct task_struct *eldest_child (struct task_struct *p) +{ +if (list_empty (&p->children))return NULL ; + return list_entry(p->children.next,struct task_struct,sibling); +} + +static inline struct task_struct *older_sibling (struct task_struct *p) +{ +if (p->sibling.prev==&p->parent->children)return NULL ; + return list_entry(p->sibling.prev,struct task_struct,sibling); +} + +static inline struct task_struct *younger_sibling (struct task_struct *p) +{ +if (p->sibling.next==&p->parent->children)return NULL ; + return list_entry(p->sibling.next,struct task_struct,sibling); +} +static void show_task (task_t * p) {unsigned long free =0 ;
kernel/signal.c +30 -0
@@ -160,6 +160,36 @@ int max_queued_signals = 1024;static int __send_sig_info (int sig,struct siginfo *info,struct task_struct *p); +/* +* Re-calculate pending state from the set of locally pending +* signals, globally pending signals, and blocked signals. +*/ +static inline int has_pending_signals (sigset_t *signal,sigset_t *blocked) +{ +unsigned long ready; +long i; + +switch (_NSIG_WORDS) { +default : +for (i = _NSIG_WORDS, ready =0 ; --i >=0 ;) + ready |= signal->sig[i] &~ blocked->sig[i]; +break ; + +case 4 : ready = signal->sig[3 ] &~ blocked->sig[3 ]; + ready |= signal->sig[2 ] &~ blocked->sig[2 ]; + ready |= signal->sig[1 ] &~ blocked->sig[1 ]; + ready |= signal->sig[0 ] &~ blocked->sig[0 ]; +break ; + +case 2 : ready = signal->sig[1 ] &~ blocked->sig[1 ]; + ready |= signal->sig[0 ] &~ blocked->sig[0 ]; +break ; + +case 1 : ready = signal->sig[0 ] &~ blocked->sig[0 ]; + } +return ready !=0 ; +} +#define PENDING (p,b) has_pending_signals(&(p)->signal, (b))void recalc_sigpending_tsk (struct task_struct *t)
Quoted 1 line · William Lee Irwin III
Quoted 1 line
This removes a bunch of inlines used only in isolated places from
sched.h
Quoted 3 lines · William Lee Irwin III
Hmm, while I'm at it, this applies atop the previous patch:
This removesd_path()fromsched.hand uninlines it. No idea why it was insched.hin the first place (or why something this large is inlined).
Atop the d_path() removal patch:
__d_path() may be privatized since umsdos is broken anyway.
fs/dcache.c | 6 +++--- include/linux/dcache.h | 2 -- kernel/ksyms.c | 1 - 3 files changed, 3 insertions(+), 6 deletions(-)
fs/dcache.c +3 -3
@@ -1136,9 +1136,9 @@ void d_move(struct dentry * dentry, stru* * "buflen" should be %PAGE_SIZE or more. Caller holds the dcache_lock. */ -char *__d_path (struct dentry *dentry,struct vfsmount *vfsmnt, -struct dentry *root,struct vfsmount *rootmnt, -char *buffer,int buflen) +static char *__d_path (struct dentry *dentry,struct vfsmount *vfsmnt, +struct dentry *root,struct vfsmount *rootmnt, +char *buffer,int buflen) {char * end = buffer+buflen;char * retval;
include/linux/dcache.h +0 -2
@@ -238,8 +238,6 @@ extern struct dentry * __d_lookup(struct/* validate "insecure" dentry pointer */ extern int d_validate (struct dentry *,struct dentry *); -extern char *__d_path (struct dentry *,struct vfsmount *,struct dentry *, -struct vfsmount *,char *,int );extern char *d_path (struct dentry *,struct vfsmount *,char *,int );/* Allocation counts.. */
kernel/ksyms.c +0 -1
@@ -167,7 +167,6 @@ EXPORT_SYMBOL(d_alloc_anon);EXPORT_SYMBOL (d_splice_alias);EXPORT_SYMBOL (d_lookup);EXPORT_SYMBOL (d_path); -EXPORT_SYMBOL (__d_path);EXPORT_SYMBOL (mark_buffer_dirty);EXPORT_SYMBOL (end_buffer_io_sync);EXPORT_SYMBOL (__mark_inode_dirty);