Re: [RFC][PATCH] Scalable Scheduling

Linus Torvalds (torvalds@transmeta.com)
Wed, 8 Aug 2001 12:14:32 -0700 (PDT)


On Wed, 8 Aug 2001, Daniel Phillips wrote:
>
> write:
>
> inline int nr_running(void)
> {
> #ifdef CONFIG_SMP
> int i = 0, tot=nt_running(REALTIME_RQ);
> while (i < smp_num_cpus) {
> tot += nt_running(cpu_logical_map(i++));
> }
> return(tot);
> #else
> return nr_running;
> #endif
> }

Even more preferably, just have (in a header file)

#ifdef CONFIG_SMP

inline int nr_running(void)
{
...
}

.. other SMP cases ..

#else

#define nr_running() (__nr_running)

.. other UP cases ..

#endif

if you just cannot make an efficient function that just works for both.

No, we don't adhere to this everywhere. But we should (and largely _do_)
try to.

Having the #ifdef's outside the code tends to have two advantages:

- it makes the code much more readable, and doesn't split things up.

- you have to choose your abstraction interfaces more carefully, which in
turn tends to make for better code.

Abstraction is nice - _especially_ when you have a compiler that sees
through the abstraction and can generate code as if it wasn't there.

Linus

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/