Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 81e294cb authored by Richard Cochran's avatar Richard Cochran Committed by Thomas Gleixner
Browse files

posix-timers: Add support for fd based clocks



Extend the negative clockids which are currently used by posix cpu
timers to encode the PID with a file descriptor based type which
encodes the fd in the upper bits.

Originally-from: Richard Cochran <richard.cochran@omicron.at>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Acked-by: default avatarJohn Stultz <johnstul@us.ibm.com>
LKML-Reference: <20110201134420.062860200@linutronix.de>
parent ce26efde
Loading
Loading
Loading
Loading
+13 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,17 @@ struct cpu_timer_list {
	int firing;
	int firing;
};
};


/*
 * Bit fields within a clockid:
 *
 * The most significant 29 bits hold either a pid or a file descriptor.
 *
 * Bit 2 indicates whether a cpu clock refers to a thread or a process.
 *
 * Bits 1 and 0 give the type: PROF=0, VIRT=1, SCHED=2, or FD=3.
 *
 * A clockid is invalid if bits 2, 1, and 0 are all set.
 */
#define CPUCLOCK_PID(clock)		((pid_t) ~((clock) >> 3))
#define CPUCLOCK_PID(clock)		((pid_t) ~((clock) >> 3))
#define CPUCLOCK_PERTHREAD(clock) \
#define CPUCLOCK_PERTHREAD(clock) \
	(((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
	(((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
@@ -29,6 +40,8 @@ struct cpu_timer_list {
#define CPUCLOCK_VIRT		1
#define CPUCLOCK_VIRT		1
#define CPUCLOCK_SCHED		2
#define CPUCLOCK_SCHED		2
#define CPUCLOCK_MAX		3
#define CPUCLOCK_MAX		3
#define CLOCKFD			CPUCLOCK_MAX
#define CLOCKFD_MASK		(CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK)


#define MAKE_PROCESS_CPUCLOCK(pid, clock) \
#define MAKE_PROCESS_CPUCLOCK(pid, clock) \
	((~(clockid_t) (pid) << 3) | (clockid_t) (clock))
	((~(clockid_t) (pid) << 3) | (clockid_t) (clock))
+1 −1
Original line number Original line Diff line number Diff line
@@ -488,7 +488,7 @@ static void release_posix_timer(struct k_itimer *tmr, int it_id_set)
static struct k_clock *clockid_to_kclock(const clockid_t id)
static struct k_clock *clockid_to_kclock(const clockid_t id)
{
{
	if (id < 0)
	if (id < 0)
		return &clock_posix_cpu;
		return (id & CLOCKFD_MASK) == CLOCKFD ? NULL : &clock_posix_cpu;


	if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
	if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
		return NULL;
		return NULL;