Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp829535ybn; Tue, 24 Sep 2019 10:07:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqyhB6CuD/EsgGFJ1v6btAQKVnr/lzExZqzaMjt9LTyLSpAq7/OkaA7beh6zMeFUymcbuEqj X-Received: by 2002:a5d:67c3:: with SMTP id n3mr3215728wrw.294.1569344877630; Tue, 24 Sep 2019 10:07:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569344877; cv=none; d=google.com; s=arc-20160816; b=YZ+PfEeCPa4tFteNEGvTfuz6UoYOtokxosDqV9vr1W6ccv7GHnPQ35wAAxMGkkF+GG Sl+s3i4KhPnIYjSFZlEKwYT+SXbUVQ8NwMxNJttC+r7WhpnQtUodxuZ18vVvCUR6XL7x Zd6kOfJW9QsJhPK7MNIjuLQ82UrxsnRU4EzpHDbSh42IiPfdTdDgA8DyfLXeYF37q9vf eg0NgDaB6fy7vCWTyZPsOb18puANoHZvCm+sFHr95rj1efNaZKRnzoZROs/pSFpvMVm+ Rtfw34+DqTv9ilg2oeT/PbUIZ31Nw0v4U0iw2zbwqKpBR+J2ArWuTb6oypqDAOBV25pl A97Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date; bh=QmuNxwkhQ8xnS3bm0ZzAXD07niL4K18quLdeOniw/hE=; b=hRzp6K2rQvxO8YXG+lMzMGhl014GPa+ilMN8kiD6OfKj8Hq/rDcdJag8bQfMMSBrQs Do9+mbOAemyNcdMH1i37Ti6nC2kNaFcObTnTapfGS0nkbs2/XJi+ll629Vhr74TnXOxY whztRAqdU/bw9WhUwr+MQGH8z1Og4KqMhHXHBU5nq2uxR6Ya9s+KIy/D6WtYb8IkAjAn jx1WCTg4/sKraXOhg/BOU/HeEshdzosZdCEr+odjKvcp2xlwWcHqOFJojjrUlKd3Pc0/ YgGnRVDNuyjJpYkzj7bOeVK26TCRLmV8kjcv3/RA72vtXboTJ4WmTrGY5ScnLYaeZ7sm 8eXA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y54si1617053edb.217.2019.09.24.10.07.34; Tue, 24 Sep 2019 10:07:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2395505AbfIWNF4 (ORCPT + 99 others); Mon, 23 Sep 2019 09:05:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47414 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2395472AbfIWNFz (ORCPT ); Mon, 23 Sep 2019 09:05:55 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8F78C307D983; Mon, 23 Sep 2019 13:05:54 +0000 (UTC) Received: from asgard.redhat.com (unknown [10.36.112.10]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AF5F35D9D5; Mon, 23 Sep 2019 13:05:51 +0000 (UTC) Date: Mon, 23 Sep 2019 15:05:31 +0200 From: Eugene Syromiatnikov To: John Stultz , Thomas Gleixner , Stephen Boyd Cc: Frederic Weisbecker , Sebastian Andrzej Siewior , "Eric W. Biederman" , linux-kernel@vger.kernel.org Subject: [PATCH v2] uapi, posix-timers: provide clockid-related macros and functions to UAPI Message-ID: <20190923130531.GA27774@asgard.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Mon, 23 Sep 2019 13:05:54 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As of now, there is no interface exposed for converting pid/fd into clockid and vice versa; linuxptp, for example, has been carrying these definitions in missing.h header for quite some time[1]. [1] https://sourceforge.net/p/linuxptp/code/ci/af380e86/tree/missing.h Signed-off-by: Eugene Syromiatnikov --- Changes since v1[1]: * Actually tried to build with the patch and fixed the build error reported by kbuild test robot[2]. [1] https://lkml.org/lkml/2019/9/20/698 [2] https://lkml.org/lkml/2019/9/22/13 --- include/linux/posix-timers.h | 47 +------------------------------------------ include/uapi/linux/time.h | 48 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 46 deletions(-) diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h index 3d10c84..ddc7e6e6 100644 --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h @@ -4,58 +4,13 @@ #include #include +#include #include #include struct kernel_siginfo; struct task_struct; -/* - * 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_PERTHREAD(clock) \ - (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0) - -#define CPUCLOCK_PERTHREAD_MASK 4 -#define CPUCLOCK_WHICH(clock) ((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK) -#define CPUCLOCK_CLOCK_MASK 3 -#define CPUCLOCK_PROF 0 -#define CPUCLOCK_VIRT 1 -#define CPUCLOCK_SCHED 2 -#define CPUCLOCK_MAX 3 -#define CLOCKFD CPUCLOCK_MAX -#define CLOCKFD_MASK (CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK) - -static inline clockid_t make_process_cpuclock(const unsigned int pid, - const clockid_t clock) -{ - return ((~pid) << 3) | clock; -} -static inline clockid_t make_thread_cpuclock(const unsigned int tid, - const clockid_t clock) -{ - return make_process_cpuclock(tid, clock | CPUCLOCK_PERTHREAD_MASK); -} - -static inline clockid_t fd_to_clockid(const int fd) -{ - return make_process_cpuclock((unsigned int) fd, CLOCKFD); -} - -static inline int clockid_to_fd(const clockid_t clk) -{ - return ~(clk >> 3); -} - #ifdef CONFIG_POSIX_TIMERS /** diff --git a/include/uapi/linux/time.h b/include/uapi/linux/time.h index 958932e..58a78a7 100644 --- a/include/uapi/linux/time.h +++ b/include/uapi/linux/time.h @@ -70,4 +70,52 @@ struct itimerval { */ #define TIMER_ABSTIME 0x01 +/* + * 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_PERTHREAD(clock) \ + (((clock) & (__kernel_clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0) + +#define CPUCLOCK_PERTHREAD_MASK 4 +#define CPUCLOCK_WHICH(clock) \ + ((clock) & (__kernel_clockid_t) CPUCLOCK_CLOCK_MASK) +#define CPUCLOCK_CLOCK_MASK 3 +#define CPUCLOCK_PROF 0 +#define CPUCLOCK_VIRT 1 +#define CPUCLOCK_SCHED 2 +#define CPUCLOCK_MAX 3 +#define CLOCKFD CPUCLOCK_MAX +#define CLOCKFD_MASK (CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK) + +static inline __kernel_clockid_t make_process_cpuclock(const unsigned int pid, + const clockid_t clock) +{ + return ((~pid) << 3) | clock; +} +static inline __kernel_clockid_t make_thread_cpuclock(const unsigned int tid, + const clockid_t clock) +{ + return make_process_cpuclock(tid, clock | CPUCLOCK_PERTHREAD_MASK); +} + +static inline __kernel_clockid_t fd_to_clockid(const int fd) +{ + return make_process_cpuclock((unsigned int) fd, CLOCKFD); +} + +static inline int clockid_to_fd(const __kernel_clockid_t clk) +{ + return ~(clk >> 3); +} + + #endif /* _UAPI_LINUX_TIME_H */ -- 2.1.4