Re: Linux 3.1-rc9

From: Ingo Molnar
Date: Mon Oct 17 2011 - 01:00:00 EST



* Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:

> However, I don't see why that spinlock is needed at all. Why aren't
> those fields just atomics (or at least just "sum_exec_runtime")?
> And why does "cputime_add()" exist at all? [...]

Agreed, atomic64_t is the best choice here. (When the lock was added
to struct *_cputimer this should probably have been done already -
but we didn't have atomic64_t back then yet.)

> That stupid definition of cputime_add() has apparently existed
> as-is since it was introduced in 2005. Why do we have code like
> this:
>
> times->utime = cputime_add(times->utime, t->utime);
>
> instead of just
>
> times->utime += t->utime;
>
> which seems not just shorter, but more readable too? The reason is
> not some type safety in the cputime_add() thing, it's just a macro.

Yes. This was in fact how the old scheduler accunting code looked
like:

- utime += t->utime;
- stime += t->stime;
+ utime = cputime_add(utime, t->utime);
+ stime = cputime_add(stime, t->stime);

before the pointless looking cputime_t wrappery was added in 2005:

0a71336: [PATCH] cputime: introduce cputime

For the record, i absolutely hate much of the other time related type
obfuscation we do as well.

For example the ktime_t obfuscation - we only do it to avoid a divide
on 32-bit architectures that cannot do fast 64/32 divisions ...

It makes the time code a *lot* less obvious than it could be.

I think we should use one flat u64 nanoseconds time type in the
kernel (preparing it with using KTIME_SCALAR on all architectures for
a release or so), used with very simple and obvious C arithmetics.

That simple time type could then trickle down as well: we could use
it everywhere in kernel code and limit the hodge-podge of ABI time
units to the syscall boundary. (and convert the internal time unit to
whatever ABI unit there is close to the syscall boundary)

There's a point where micro-optimized 32-bit support related
maintenance overhead (and the resulting loss of
robustness/flexibility) becomes too expensive IMO.

Thanks,

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