* [patch 2.6.7-rc2] Add const to some scheduling functions
@ 2004-06-01 3:46 Keith Owens
2004-06-01 7:16 ` Andrew Morton
0 siblings, 1 reply; 4+ messages in thread
From: Keith Owens @ 2004-06-01 3:46 UTC (permalink / raw)
To: linux-kernel
Several scheduler macros only read from the task struct, mark them
const. It can generate better code.
Index: 2.6.7-rc2/include/linux/sched.h
===================================================================
--- 2.6.7-rc2.orig/include/linux/sched.h Mon May 31 09:52:55 2004
+++ 2.6.7-rc2/include/linux/sched.h Tue Jun 1 13:40:51 2004
@@ -681,9 +681,9 @@ extern void sched_balance_exec(void);
extern void sched_idle_next(void);
extern void set_user_nice(task_t *p, long nice);
-extern int task_prio(task_t *p);
-extern int task_nice(task_t *p);
-extern int task_curr(task_t *p);
+extern int task_prio(const task_t *p);
+extern int task_nice(const task_t *p);
+extern int task_curr(const task_t *p);
extern int idle_cpu(int cpu);
void yield(void);
@@ -905,7 +905,7 @@ extern void wait_task_inactive(task_t *
#define while_each_thread(g, t) \
while ((t = next_thread(t)) != g)
-extern task_t * FASTCALL(next_thread(task_t *p));
+extern task_t * FASTCALL(next_thread(const task_t *p));
#define thread_group_leader(p) (p->pid == p->tgid)
@@ -1044,7 +1044,7 @@ extern void signal_wake_up(struct task_s
*/
#ifdef CONFIG_SMP
-static inline unsigned int task_cpu(struct task_struct *p)
+static inline unsigned int task_cpu(const struct task_struct *p)
{
return p->thread_info->cpu;
}
Index: 2.6.7-rc2/kernel/exit.c
===================================================================
--- 2.6.7-rc2.orig/kernel/exit.c Mon May 31 09:52:57 2004
+++ 2.6.7-rc2/kernel/exit.c Tue Jun 1 13:40:51 2004
@@ -826,10 +826,10 @@ asmlinkage long sys_exit(int error_code)
do_exit((error_code&0xff)<<8);
}
-task_t fastcall *next_thread(task_t *p)
+task_t fastcall *next_thread(const task_t *p)
{
- struct pid_link *link = p->pids + PIDTYPE_TGID;
- struct list_head *tmp, *head = &link->pidptr->task_list;
+ const struct pid_link *link = p->pids + PIDTYPE_TGID;
+ const struct list_head *tmp, *head = &link->pidptr->task_list;
#ifdef CONFIG_SMP
if (!p->sighand)
Index: 2.6.7-rc2/kernel/sched.c
===================================================================
--- 2.6.7-rc2.orig/kernel/sched.c Mon May 31 09:52:57 2004
+++ 2.6.7-rc2/kernel/sched.c Tue Jun 1 13:40:51 2004
@@ -546,7 +546,7 @@ static inline void resched_task(task_t *
* task_curr - is this task currently executing on a CPU?
* @p: the task in question.
*/
-inline int task_curr(task_t *p)
+inline int task_curr(const task_t *p)
{
return cpu_curr(task_cpu(p)) == p;
}
@@ -2640,7 +2640,7 @@ asmlinkage long sys_nice(int increment)
* RT tasks are offset by -200. Normal tasks are centered
* around 0, value goes from -16 to +15.
*/
-int task_prio(task_t *p)
+int task_prio(const task_t *p)
{
return p->prio - MAX_RT_PRIO;
}
@@ -2649,7 +2649,7 @@ int task_prio(task_t *p)
* task_nice - return the nice value of a given task.
* @p: the task in question.
*/
-int task_nice(task_t *p)
+int task_nice(const task_t *p)
{
return TASK_NICE(p);
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch 2.6.7-rc2] Add const to some scheduling functions
2004-06-01 3:46 [patch 2.6.7-rc2] Add const to some scheduling functions Keith Owens
@ 2004-06-01 7:16 ` Andrew Morton
2004-06-01 9:55 ` Keith Owens
0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2004-06-01 7:16 UTC (permalink / raw)
To: Keith Owens; +Cc: linux-kernel
Keith Owens <kaos@ocs.com.au> wrote:
>
> Several scheduler macros only read from the task struct, mark them
> const. It can generate better code.
It makes no change to the gcc-3.4.0-compiled x86 kernel's size. Under what
circumstances did you see improvements?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch 2.6.7-rc2] Add const to some scheduling functions
2004-06-01 7:16 ` Andrew Morton
@ 2004-06-01 9:55 ` Keith Owens
2004-06-01 20:12 ` Paul Jackson
0 siblings, 1 reply; 4+ messages in thread
From: Keith Owens @ 2004-06-01 9:55 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel
On Tue, 1 Jun 2004 00:16:32 -0700,
Andrew Morton <akpm@osdl.org> wrote:
>Keith Owens <kaos@ocs.com.au> wrote:
>>
>> Several scheduler macros only read from the task struct, mark them
>> const. It can generate better code.
>
>It makes no change to the gcc-3.4.0-compiled x86 kernel's size. Under what
>circumstances did you see improvements?
None, it is just good programming practice to mark parameters as const
where possible.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch 2.6.7-rc2] Add const to some scheduling functions
2004-06-01 9:55 ` Keith Owens
@ 2004-06-01 20:12 ` Paul Jackson
0 siblings, 0 replies; 4+ messages in thread
From: Paul Jackson @ 2004-06-01 20:12 UTC (permalink / raw)
To: Keith Owens; +Cc: akpm, linux-kernel
Keith wrote (of some added 'const' qualifiers):
> It can generate better code.
Later, he wrote (when asked under what circumstances he saw this):
>None, it is just good programming practice ...
So you're not saying it _does_ generate better code, but that it's
possible that it could do so, right?
In any case, the value of 'const' to me is more in documenting
the interface, and imposing compiler checked restrictions on the
implementation.
--
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <pj@sgi.com> 1.650.933.1373
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-06-01 20:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-01 3:46 [patch 2.6.7-rc2] Add const to some scheduling functions Keith Owens
2004-06-01 7:16 ` Andrew Morton
2004-06-01 9:55 ` Keith Owens
2004-06-01 20:12 ` Paul Jackson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®