Subject: Is CLOCKS_MASK macro obsolete?

The CLOCKS_MASK macro in include/uapi/linux/time.h seems broken; it's ORing together
two numbered values, one of which is 0. Perhaps these clock IDs started as a bitmask?
CLOCKS_MASK doesn't appear to be used anywhere in the kernel; nor does the adjacent
CLOCKS_MONO.

Should those macros be deleted?

Excerpt:
#define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 1
#define CLOCK_PROCESS_CPUTIME_ID 2
#define CLOCK_THREAD_CPUTIME_ID 3
#define CLOCK_MONOTONIC_RAW 4
#define CLOCK_REALTIME_COARSE 5
#define CLOCK_MONOTONIC_COARSE 6
#define CLOCK_BOOTTIME 7
#define CLOCK_REALTIME_ALARM 8
#define CLOCK_BOOTTIME_ALARM 9
/*
* The driver implementing this got removed. The clock ID is kept as a
* place holder. Do not reuse!
*/
#define CLOCK_SGI_CYCLE 10
#define CLOCK_TAI 11

#define MAX_CLOCKS 16
#define CLOCKS_MASK (CLOCK_REALTIME | CLOCK_MONOTONIC)
#define CLOCKS_MONO CLOCK_MONOTONIC



2021-10-15 07:36:14

by John Stultz

[permalink] [raw]
Subject: Re: Is CLOCKS_MASK macro obsolete?

On Thu, Oct 14, 2021 at 4:46 PM Elliott, Robert (Servers)
<[email protected]> wrote:
>
> The CLOCKS_MASK macro in include/uapi/linux/time.h seems broken; it's ORing together
> two numbered values, one of which is 0. Perhaps these clock IDs started as a bitmask?
> CLOCKS_MASK doesn't appear to be used anywhere in the kernel; nor does the adjacent
> CLOCKS_MONO.
>
> Should those macros be deleted?

As for CLOCKS_MASK, the earliest reference I can find is here:
https://elixir.bootlin.com/linux/v2.5.69/source/include/linux/time.h#L246

Right before the 2.6 release. Seems to have come in with this patch:
https://lore.kernel.org/lkml/[email protected]/
But even there, it doesn't make sense as a mask.

There was even a patch to remove it:
https://lore.kernel.org/lkml/[email protected]/

Then it took its current form with this:
https://lore.kernel.org/lkml/[email protected]/

So, yea, I suspect it can be dropped as it really doesn't make much
sense, so I don't think it's likely used anywhere in a useful way.
(Though it is referenced in some docs -
https://github.com/Abdullah-Younus/E-Project/blob/35e2d915dd17d7cd14618af8d727b2874c4cae37/doc-html/doc/rtl/linux/clocks_mask.html)

For CLOCKS_MONO, the main risk is breaking existing userland code that
uses it at build time. But as the fix changing to CLOCK_MONOTONIC
seems not too difficult, it's probably ok.

thanks
-john