Received: by 10.223.164.202 with SMTP id h10csp658064wrb; Mon, 6 Nov 2017 13:07:06 -0800 (PST) X-Google-Smtp-Source: ABhQp+RY0Ht9WP3CTMRTOk8UzDJ6EHvIU8UvKDBkJ5dIcQxWBs/9mRm+a05uzMe3WU+xZSpZZnXn X-Received: by 10.99.156.26 with SMTP id f26mr16474094pge.433.1510002426360; Mon, 06 Nov 2017 13:07:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510002426; cv=none; d=google.com; s=arc-20160816; b=jlM7+/jWt8rEf4FBYK/jY5cXivwdmK6if9AJYKdRvI8AM2n+mC41BbR3AUlygnX6PK 5Yz472fRVV1yzYmslpz1T2g4ssDRRAdGNJs6W5otLW164DsqSrizRq23+hKUow+O7SEh bYgnJpYBqY1YnNu8AAPJ8UD7fKZgMESuwgvzm1NH9l/eXhvzysyCtFSLseZF2TBAC3Ev aLAthkPJhz6z6HFsD+2et3yNbfCRPNfDFBvtXpfMx/Ad6bVX4g2gx7v/jzl+DmUxPsyH hDtVhPmntARnZEwtJp8GFmLlH6fiTDPYw2+FIqSpl9vHdRH7lvOjGcHKgsKj4aFicrzs vD8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=p7shY3lYmopEVMyz32hfKHMLqNkgqLyZZCLTgXdBksY=; b=JDVBGCsujfu7bL0Iz85X4Vj8TgNvxP2iLlK7cB2XE0RS1uqvbwls9lB/dMIpAiYLEC Kfka3cu9BScP5LP3VdZia5uwZGObV19jw6OikklqRbq/4R0urR9SDnvICLx6Sz2IZido vZjuTKFzh9uVYDpDYkI/FNDNNk5NGVrr65sgPjJMT9YviNePMKlMWHSGrEzrlwGh2/Yq LXv7uP9VIDaLYpz5ER9orC43oYoE4IUi7ZoKclTXiVedRxoosYO1IzzAvfmbH+FPTQzL +CrlznGm4xGz3gvGgi8mb/WZOmc79WYAnNAYcHQPA3m8vNjjAHQlWm+pYxARDiVSwiMs 11Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b=TFUHcsIW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=android.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k6si11822451pgt.315.2017.11.06.13.06.52; Mon, 06 Nov 2017 13:07:06 -0800 (PST) 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; dkim=pass header.i=@android.com header.s=20161025 header.b=TFUHcsIW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=android.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754129AbdKFVEJ (ORCPT + 95 others); Mon, 6 Nov 2017 16:04:09 -0500 Received: from mail-io0-f194.google.com ([209.85.223.194]:50337 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751446AbdKFVEG (ORCPT ); Mon, 6 Nov 2017 16:04:06 -0500 Received: by mail-io0-f194.google.com with SMTP id 97so17171169iok.7 for ; Mon, 06 Nov 2017 13:04:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=android.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=p7shY3lYmopEVMyz32hfKHMLqNkgqLyZZCLTgXdBksY=; b=TFUHcsIWucjRR1AkCkdQ3U2U3H9+3C7TJbUaZjvA/CzjMDXma4wyOSYaIOVfy4x7pm 8EDaubMvfhY7mDbxfrbV1x9kGfu0KnQY3xCegiinledHWtHibMjlXCKGhXH7F/LbHwn4 LltMOsBvYFCe1hb+XEN1MKAgRPeHpRwX9Y6cPN1yfeU3KRZk+JQiRE4AIugn86nQRccL jtu2BMP9ImNyEoYqOv3PxWd1x/CjXCJSAbqqCtt4tG2nYWvXi+jcEFc45e5X53eJFWNh L6FcDSZW15imNItpkiSkaY/LTwkuTkDCgUcY1eucNYQ6fxkdQu90MmkLJoQqUPXUDJMx r7hg== 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; bh=p7shY3lYmopEVMyz32hfKHMLqNkgqLyZZCLTgXdBksY=; b=U+zWpxNlhgsoZYmHYJutWRfYnQ2wLo3dunwVl6xWoBajhkJsGw26SlFml5hAGbvaIZ YewIOhtnU0QmY4ROCN0S+YLOOsgw1LxURALJW8h4ZlYR6W0T3m30vY8IIYgtzsHanfRz HIMgL8RxPk46mH5vEyG8Yyzs8Ws/RIzS/EoeLgeSbwh/KAgVSvMyKAR8ptJz4W2fUCYS rVcrXaUf6j2/Az3dL5iN+Di9DfP4l2jRA0JC48WR8K9Sv7KBwCa7IY0eB5I3OmhC8HXl 1T3/P4tD7gMSy59SqzQz5n0kP0IZrqkj9DISgH4YR+7eccd0aWwVXsfX7oD7lUSlPOn4 typA== X-Gm-Message-State: AJaThX6smj+Waeoc3rXRTdsDcMRFmowfw4J1rA5+5x+YVyZQrmjqBMys 40RHriksTvKPPr4acV3XgbedRvYucg8= X-Received: by 10.107.59.211 with SMTP id i202mr20777264ioa.79.1510002245192; Mon, 06 Nov 2017 13:04:05 -0800 (PST) Received: from nebulus.mtv.corp.google.com ([100.98.120.17]) by smtp.gmail.com with ESMTPSA id f70sm4954810itc.23.2017.11.06.13.04.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 06 Nov 2017 13:04:04 -0800 (PST) From: Mark Salyzyn To: linux-kernel@vger.kernel.org Cc: Mark Salyzyn , James Morse , Russell King , Catalin Marinas , Will Deacon , Andy Lutomirski , Dmitry Safonov , John Stultz , Mark Rutland , Laura Abbott , Kees Cook , Ard Biesheuvel , Andy Gross , Kevin Brodsky , Andrew Pinski , Thomas Gleixner , linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 11/12] lib: vdso: Add support for CLOCK_BOOTTIME Date: Mon, 6 Nov 2017 13:03:50 -0800 Message-Id: <20171106210401.95320-1-salyzyn@android.com> X-Mailer: git-send-email 2.15.0.403.gc27cc4dac6-goog Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Take an effort to recode the arm64 vdso code from assembler to C previously submitted by Andrew Pinski , rework it for use in both arm and arm64, overlapping any optimizations for each architecture. But instead of landing it in arm64, land the result into lib/vdso and unify both implementations to simplify future maintenance. Add a case for CLOCK_BOOTTIME as it is popular for measuring relative time on systems expected to suspend() or hibernate(). Android uses CLOCK_BOOTTIME for all relative time measurements and timeouts. Switching to vdso reduced CPU utilization and improves accuracy. There is also a desire by some partners to switch all logging over to CLOCK_BOOTTIME, and thus this operation alone would contribute to a near percentile CPU load. Signed-off-by: Mark Salyzyn Cc: James Morse Cc: Russell King Cc: Catalin Marinas Cc: Will Deacon Cc: Andy Lutomirski Cc: Dmitry Safonov Cc: John Stultz Cc: Mark Rutland Cc: Laura Abbott Cc: Kees Cook Cc: Ard Biesheuvel Cc: Andy Gross Cc: Kevin Brodsky Cc: Andrew Pinski Cc: Thomas Gleixner Cc: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org v2: - rebased and changed from 3/3 to 10/10, fortified commit message. v3: - move arch/arm/vdso/vgettimeofday.c to lib/vdso/vgettimeofday.c. v4: - update commit message to reflect specific, and overall reasoning of patch series. - drop forced inline operations. - switch typeof() with __kernel_time_t. v5: - added comment about open coded timepsec_add_ns() for clarity. --- arch/arm/include/asm/vdso_datapage.h | 1 + arch/arm/kernel/vdso.c | 1 + arch/arm64/include/asm/vdso_datapage.h | 1 + arch/arm64/kernel/vdso.c | 1 + lib/vdso/vgettimeofday.c | 55 ++++++++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+) diff --git a/arch/arm/include/asm/vdso_datapage.h b/arch/arm/include/asm/vdso_datapage.h index 1c6e6a5d5d9d..1adfb2daac3a 100644 --- a/arch/arm/include/asm/vdso_datapage.h +++ b/arch/arm/include/asm/vdso_datapage.h @@ -64,6 +64,7 @@ struct vdso_data { u32 tz_minuteswest; /* timezone info for gettimeofday(2) */ u32 tz_dsttime; + u64 btm_nsec; /* monotonic to boot time */ /* Raw clocksource multipler */ u32 cs_raw_mult; /* Raw time */ diff --git a/arch/arm/kernel/vdso.c b/arch/arm/kernel/vdso.c index a80c58805699..d3ec878c5809 100644 --- a/arch/arm/kernel/vdso.c +++ b/arch/arm/kernel/vdso.c @@ -347,6 +347,7 @@ void update_vsyscall(struct timekeeper *tk) /* tkr_mono.shift == tkr_raw.shift */ vdso_data->cs_shift = tk->tkr_mono.shift; vdso_data->cs_mask = tk->tkr_mono.mask; + vdso_data->btm_nsec = ktime_to_ns(tk->offs_boot); } vdso_write_end(vdso_data); diff --git a/arch/arm64/include/asm/vdso_datapage.h b/arch/arm64/include/asm/vdso_datapage.h index 95f4a7abab80..e4fa5e054708 100644 --- a/arch/arm64/include/asm/vdso_datapage.h +++ b/arch/arm64/include/asm/vdso_datapage.h @@ -45,6 +45,7 @@ struct vdso_data { __u64 xtime_coarse_nsec; __u64 wtm_clock_sec; /* Wall to monotonic time */ vdso_wtm_clock_nsec_t wtm_clock_nsec; + __u64 btm_nsec; /* monotonic to boot time */ __u32 tb_seq_count; /* Timebase sequence counter */ /* cs_* members must be adjacent and in this order (ldp accesses) */ __u32 cs_mono_mult; /* NTP-adjusted clocksource multiplier */ diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c index 59f150c25889..0710edd8bedc 100644 --- a/arch/arm64/kernel/vdso.c +++ b/arch/arm64/kernel/vdso.c @@ -243,6 +243,7 @@ void update_vsyscall(struct timekeeper *tk) vdso_data->cs_raw_mult = tk->tkr_raw.mult; /* tkr_mono.shift == tkr_raw.shift */ vdso_data->cs_shift = tk->tkr_mono.shift; + vdso_data->btm_nsec = ktime_to_ns(tk->offs_boot); } smp_wmb(); diff --git a/lib/vdso/vgettimeofday.c b/lib/vdso/vgettimeofday.c index 33c5917fe9f8..d64f60010bb2 100644 --- a/lib/vdso/vgettimeofday.c +++ b/lib/vdso/vgettimeofday.c @@ -247,6 +247,50 @@ static notrace int do_monotonic_raw(const struct vdso_data *vd, return 0; } +static notrace int do_boottime(const struct vdso_data *vd, struct timespec *ts) +{ + u32 seq, mult, shift; + u64 nsec, cycle_last, wtm_nsec; +#ifdef ARCH_CLOCK_FIXED_MASK + static const u64 mask = ARCH_CLOCK_FIXED_MASK; +#else + u64 mask; +#endif + __kernel_time_t sec; + + do { + seq = vdso_read_begin(vd); + + if (vd->use_syscall) + return -1; + + cycle_last = vd->cs_cycle_last; + + mult = vd->cs_mono_mult; + shift = vd->cs_shift; +#ifndef ARCH_CLOCK_FIXED_MASK + mask = vd->cs_mask; +#endif + + sec = vd->xtime_clock_sec; + nsec = vd->xtime_clock_snsec; + + sec += vd->wtm_clock_sec; + wtm_nsec = vd->wtm_clock_nsec + vd->btm_nsec; + + } while (unlikely(vdso_read_retry(vd, seq))); + + nsec += get_clock_shifted_nsec(cycle_last, mult, mask); + nsec >>= shift; + nsec += wtm_nsec; + + /* open coding timespec_add_ns to save a ts->tv_nsec = 0 */ + ts->tv_sec = sec + __iter_div_u64_rem(nsec, NSEC_PER_SEC, &nsec); + ts->tv_nsec = nsec; + + return 0; +} + #else /* ARCH_PROVIDES_TIMER */ static notrace int do_realtime(const struct vdso_data *vd, struct timespec *ts) @@ -265,6 +309,12 @@ static notrace int do_monotonic_raw(const struct vdso_data *vd, return -1; } +static notrace int do_boottime(const struct vdso_data *vd, + struct timespec *ts) +{ + return -1; +} + #endif /* ARCH_PROVIDES_TIMER */ notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts) @@ -290,6 +340,10 @@ notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts) if (do_monotonic_raw(vd, ts)) goto fallback; break; + case CLOCK_BOOTTIME: + if (do_boottime(vd, ts)) + goto fallback; + break; default: goto fallback; } @@ -326,6 +380,7 @@ int __vdso_clock_getres(clockid_t clock, struct timespec *res) long nsec; if (clock == CLOCK_REALTIME || + clock == CLOCK_BOOTTIME || clock == CLOCK_MONOTONIC || clock == CLOCK_MONOTONIC_RAW) nsec = MONOTONIC_RES_NSEC; -- 2.15.0.403.gc27cc4dac6-goog From 1583351896671628411@xxx Mon Nov 06 21:00:37 +0000 2017 X-GM-THRID: 1581419883717791265 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread