From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1182C433E1 for ; Thu, 16 Jul 2020 05:13:28 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6EDD3207BB for ; Thu, 16 Jul 2020 05:13:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="0y4uwsIq"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Gt773ugE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6EDD3207BB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=2nnOIfEApDKt3t2ahW4Kj/yG55dvDBr7SjFiYk6WzBI=; b=0y4uwsIqDAOLvUqsemOkQou882 Cwl6KKnKSWZrFHSyOuY127lLzx1rWXTxa49PXAcRMRH9buY6Kcvrvbc4XlppR2anp9xAp86tExVHS oPpP3XbBz/H/hy8tOYw7yV0cn9245HeTxDwIvIjNUW0dKqjTvNk8VjiKopBx8Dj8vhwhUmsY5uDTv D2C6jYLW2F/9vaNy4nLSw45iQ3U4YklGgu7XsIKvCFab8jG64+9GpQvQ92ytS95tRq1gxAvDEW6X1 hsTWMuPPkpooLaLnVx3k0qXm9bMoJaJhyxECv/V0ASh9oy5WvoVAKhibL2+a9tn8CQldTEjxEqKQv 7c/f8Hrg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jvwBf-0005TZ-Gv; Thu, 16 Jul 2020 05:12:03 +0000 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jvwBd-0005SL-Ae for linux-arm-kernel@lists.infradead.org; Thu, 16 Jul 2020 05:12:02 +0000 Received: by mail-pj1-x1044.google.com with SMTP id f16so4084530pjt.0 for ; Wed, 15 Jul 2020 22:12:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZudUuOTNYLjrn927Wl/0yhsw+jXTcOSpfU/HEVcjSaU=; b=Gt773ugE0h5EgoccjmZl2Lzgz6qbZQF7ighWOfIN6A3dQJnKxXJTf185l8MbquwkH3 A3+XGKXQKfOqQSFhrCa1bopgyeKqM0oKMe2twwL7IkCP8d9+QlGYBdOryOLalN4+pQPz IwdoyQj455gQ21EVTpL8VZ9ZFKuk7aOM+muj+xJV3nA+tnIzKQ9Fxw3QmBcMDNKDnsW7 KCgGh2vQQF69RT8FkDYELw2fVMBW78CdrIZvnieOJ5pX66eEAKt0fdlk2PlTDi7TNEoc 4SrCSCkMBcJPbPI3ktSXHbeZ8MbcQa++cZT4ln3YNWt4nvwMfLtGsq6smxxCsh2MZG2F w0Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZudUuOTNYLjrn927Wl/0yhsw+jXTcOSpfU/HEVcjSaU=; b=NABUG+/RZ5wkScfAWrZ/rvMwgL/7N/C8ZIRvL91tt3RCI/DPq66Q+K8MWu0k7P+1yp sr0V/xoi42gdqp/zUyj9fEVNPLU/c6cZ+FkyhbNnku6mgIUlaYQf5/hg3cLy1bGn/yTZ bCrjDnAIOWQqy//l5cbR1qutyAxVi/Ks5pMvZd3wmZkfM+tmqBJ4rCWTI4ids2U/eQ0n 12sl1q1dRBPbnv0kAvFjBbxUpX8mej6y+vsoNWGtOuQ3yVrd2n4XI+3Hig8nXyvcwf5X M+MSgnOnhh5aGcRJtge1mGHsKaIqsMTEvLr/uQiUh+ypOWvoSoe1b/BH2qs4okgWzy7V Lgxw== X-Gm-Message-State: AOAM530I5b+D2R8quhQPUq4RK/s+jW46t12SqTp5LHouaia9Cc4JaEqa Fk9SmvlpH90X7UprpCjJ3w55fg== X-Google-Smtp-Source: ABdhPJxLGTY7dEuWAlIYrXYOh6qTVtPq90fdCUjRoXKAII2jiuebeKM7/zHYlSqnZ/kmm1PEMSqrCg== X-Received: by 2002:a17:90a:7406:: with SMTP id a6mr2798818pjg.152.1594876319114; Wed, 15 Jul 2020 22:11:59 -0700 (PDT) Received: from localhost ([2400:8904::f03c:91ff:fe8a:bbe4]) by smtp.gmail.com with ESMTPSA id l17sm3701086pgn.48.2020.07.15.22.11.57 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 Jul 2020 22:11:58 -0700 (PDT) From: Leo Yan To: Peter Zijlstra , Will Deacon , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Catalin Marinas , Thomas Gleixner , "Ahmed S. Darwish" , "Ben Dooks (Codethink)" , Paul Cercueil , Adrian Hunter , Kan Liang , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 1/7] sched_clock: Expose struct clock_read_data Date: Thu, 16 Jul 2020 13:11:24 +0800 Message-Id: <20200716051130.4359-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200716051130.4359-1-leo.yan@linaro.org> References: <20200716051130.4359-1-leo.yan@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200716_011201_391322_A096BFC3 X-CRM114-Status: GOOD ( 15.75 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leo Yan MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Peter Zijlstra In order to support perf_event_mmap_page::cap_time features, an architecture needs, aside from a userspace readable counter register, to expose the exact clock data so that userspace can convert the counter register into a correct timestamp. Provide struct clock_read_data and two (seqcount) helpers so that architectures (arm64 in specific) can expose the numbers to userspace. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Leo Yan --- include/linux/sched_clock.h | 28 +++++++++++++++++++++++++ kernel/time/sched_clock.c | 41 ++++++++++++------------------------- 2 files changed, 41 insertions(+), 28 deletions(-) diff --git a/include/linux/sched_clock.h b/include/linux/sched_clock.h index 0bb04a96a6d4..528718e4ed52 100644 --- a/include/linux/sched_clock.h +++ b/include/linux/sched_clock.h @@ -6,6 +6,34 @@ #define LINUX_SCHED_CLOCK #ifdef CONFIG_GENERIC_SCHED_CLOCK +/** + * struct clock_read_data - data required to read from sched_clock() + * + * @epoch_ns: sched_clock() value at last update + * @epoch_cyc: Clock cycle value at last update. + * @sched_clock_mask: Bitmask for two's complement subtraction of non 64bit + * clocks. + * @read_sched_clock: Current clock source (or dummy source when suspended). + * @mult: Multipler for scaled math conversion. + * @shift: Shift value for scaled math conversion. + * + * Care must be taken when updating this structure; it is read by + * some very hot code paths. It occupies <=40 bytes and, when combined + * with the seqcount used to synchronize access, comfortably fits into + * a 64 byte cache line. + */ +struct clock_read_data { + u64 epoch_ns; + u64 epoch_cyc; + u64 sched_clock_mask; + u64 (*read_sched_clock)(void); + u32 mult; + u32 shift; +}; + +extern struct clock_read_data *sched_clock_read_begin(unsigned int *seq); +extern int sched_clock_read_retry(unsigned int seq); + extern void generic_sched_clock_init(void); extern void sched_clock_register(u64 (*read)(void), int bits, diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c index fa3f800d7d76..0acaadc3156c 100644 --- a/kernel/time/sched_clock.c +++ b/kernel/time/sched_clock.c @@ -19,31 +19,6 @@ #include "timekeeping.h" -/** - * struct clock_read_data - data required to read from sched_clock() - * - * @epoch_ns: sched_clock() value at last update - * @epoch_cyc: Clock cycle value at last update. - * @sched_clock_mask: Bitmask for two's complement subtraction of non 64bit - * clocks. - * @read_sched_clock: Current clock source (or dummy source when suspended). - * @mult: Multipler for scaled math conversion. - * @shift: Shift value for scaled math conversion. - * - * Care must be taken when updating this structure; it is read by - * some very hot code paths. It occupies <=40 bytes and, when combined - * with the seqcount used to synchronize access, comfortably fits into - * a 64 byte cache line. - */ -struct clock_read_data { - u64 epoch_ns; - u64 epoch_cyc; - u64 sched_clock_mask; - u64 (*read_sched_clock)(void); - u32 mult; - u32 shift; -}; - /** * struct clock_data - all data needed for sched_clock() (including * registration of a new clock source) @@ -93,6 +68,17 @@ static inline u64 notrace cyc_to_ns(u64 cyc, u32 mult, u32 shift) return (cyc * mult) >> shift; } +struct clock_read_data *sched_clock_read_begin(unsigned int *seq) +{ + *seq = raw_read_seqcount(&cd.seq); + return cd.read_data + (*seq & 1); +} + +int sched_clock_read_retry(unsigned int seq) +{ + return read_seqcount_retry(&cd.seq, seq); +} + unsigned long long notrace sched_clock(void) { u64 cyc, res; @@ -100,13 +86,12 @@ unsigned long long notrace sched_clock(void) struct clock_read_data *rd; do { - seq = raw_read_seqcount(&cd.seq); - rd = cd.read_data + (seq & 1); + rd = sched_clock_read_begin(&seq); cyc = (rd->read_sched_clock() - rd->epoch_cyc) & rd->sched_clock_mask; res = rd->epoch_ns + cyc_to_ns(cyc, rd->mult, rd->shift); - } while (read_seqcount_retry(&cd.seq, seq)); + } while (sched_clock_read_retry(seq)); return res; } -- 2.17.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel