From patchwork Fri Jul 20 00:38:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 142389 Delivered-To: patches@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2346257ljj; Thu, 19 Jul 2018 17:38:55 -0700 (PDT) X-Received: by 2002:a62:2744:: with SMTP id n65-v6mr7901110pfn.125.1532047134886; Thu, 19 Jul 2018 17:38:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532047134; cv=none; d=google.com; s=arc-20160816; b=rRG3DD1JYOZNTvpevDceJzC6OGB8dAMyLG6371tp8k5PtQnGAwkEdr22NSaJkDXdQI oqMvbHyTTJTWkFeLWpaW7y2pVA4d09gcPqB5XuwS0NRoe7SQQwYpQtpGXsaZcuwiWyvf CUao5eDdqcM63qJCeXc//QcIXBaOmi2qQS7Szpi76cDnOKVWJB2KW9xijhj4s3hxOqIH 5CzM8Pef7UCLy3BH/DwoUKv5WNmQLncTH03VF6/HIRA1IGVXSHi8HThoglMTIYKXEm5Y 9O2j697FaF6++eARZIiUDyPS/FuFnqOeph2dhqguqKHbhva3JKk0zoE57xkaWao392Vc 1Kzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=Dw/oxzW8/jxmVrKujqloAZWpXoumHLdiLMxwHNKgBis=; b=RW+K9lKupswdDcwUdXCpnJF5zYdv6sgFyO3+i5hYWwuzFvt/96SphGKD0sxcZ6tDb5 5H+RDmrQ01+Oh4p4YQwcujrgJ0jO2nC9cPr+IQiyuoHkJiAxZ7tozPmFL3Lyr/xbZ+/w Z11LIVEc7BnyuTBLYcOGQG7btLcPJ2zxfZflJJKK6zhCx+/Gb9Aq2K1+YGo215kn7Hjx DsuFWdGJ05uXzU9r99piLImDb/3F1pMkteFciMRO2hXGVmbvTxphOZSgyhd2m0+8stOF jv3hr5rrvReDnWs8Me1jRvIY3cVgHsVSc/W2Ie8RqJ480b3yYPb20VZJqs/eG5BLuyxF Ocfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Jf2R5AZm; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id r19-v6sor138957pgl.272.2018.07.19.17.38.54 for (Google Transport Security); Thu, 19 Jul 2018 17:38:54 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Jf2R5AZm; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=Dw/oxzW8/jxmVrKujqloAZWpXoumHLdiLMxwHNKgBis=; b=Jf2R5AZmRlR1FrKf0N8PUA60L9fHAFGCMl+kwD9C5lcKya1wGSGf4qfQepewreL+M+ 1oVSk1Nid2kSvQCCPW0R9Z72a1cYhUhwzBmShS591/Pt3zhqSlTcPT8LH4RQxFavlCHb Cl+aKB4h9pn7BWnTyD9ePGP8+t2lB7iHB2KtU= 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=Dw/oxzW8/jxmVrKujqloAZWpXoumHLdiLMxwHNKgBis=; b=GqtDmAyeFIcNhhQI8+UH33wxfX2IilWKT/E0uK2sPrhYve9tgPk8VBtj/wozFwklpF b2S5vmz2IEHS1zTCv5Bb2tDH4RbvNgeXjjhCYkRP9+BX73IGmfTSzFV6RyYybrepES9r Iq/1gvhqeaHixb6FiNoq5bAtaaZ4IWn00IPiUWdhaoUhmdNXSNysqb0I6TyGwLonl7t1 z1iElyt1MmQqXn7OP5TdUyhDg3YNunS2FutgRjhsapK66exi20zGDDWNmdvr1aUgx0vD kbUbsNCFla6vwlbNKiVeXQX1KWwh/BxrKTpwqg2WrWg15wrl3iEKQloLHFsfOFb6cK3w dVPw== X-Gm-Message-State: AOUpUlHw+WUrMijzcj/toUp07FkUxlbgmLx7SvY2wQzO882gozPv2k+u HBGZmd6RLOUgHdmUaKIF1AF2lbIe X-Google-Smtp-Source: AAOMgpcz3LrcLWbk5etGyhitDy3l5l4zsrpDn1Vex0AgNVP/l+K+YkkpkE/cIOBnwymGSxH2sPPcgg== X-Received: by 2002:a63:195e:: with SMTP id 30-v6mr11843169pgz.192.1532047134389; Thu, 19 Jul 2018 17:38:54 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:600:5100:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id x5-v6sm383881pfh.67.2018.07.19.17.38.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Jul 2018 17:38:53 -0700 (PDT) From: John Stultz To: lkml Cc: Ondrej Mosnacek , Thomas Gleixner , Ingo Molnar , Miroslav Lichvar , Richard Cochran , Prarit Bhargava , Stephen Boyd , John Stultz Subject: [PATCH 1/5] ntp: Remove redundant arguments Date: Thu, 19 Jul 2018 17:38:43 -0700 Message-Id: <1532047127-26699-2-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1532047127-26699-1-git-send-email-john.stultz@linaro.org> References: <1532047127-26699-1-git-send-email-john.stultz@linaro.org> From: Ondrej Mosnacek The 'ts' argument of process_adj_status() and process_adjtimex_modes() is unused and can be safely removed. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Miroslav Lichvar Cc: Richard Cochran Cc: Prarit Bhargava Cc: Stephen Boyd Signed-off-by: Ondrej Mosnacek Signed-off-by: John Stultz --- kernel/time/ntp.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) -- 2.7.4 diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 10a7905..3eddac2 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -642,7 +642,7 @@ void ntp_notify_cmos_timer(void) /* * Propagate a new txc->status value into the NTP state: */ -static inline void process_adj_status(struct timex *txc, struct timespec64 *ts) +static inline void process_adj_status(struct timex *txc) { if ((time_status & STA_PLL) && !(txc->status & STA_PLL)) { time_state = TIME_OK; @@ -665,12 +665,10 @@ static inline void process_adj_status(struct timex *txc, struct timespec64 *ts) } -static inline void process_adjtimex_modes(struct timex *txc, - struct timespec64 *ts, - s32 *time_tai) +static inline void process_adjtimex_modes(struct timex *txc, s32 *time_tai) { if (txc->modes & ADJ_STATUS) - process_adj_status(txc, ts); + process_adj_status(txc); if (txc->modes & ADJ_NANO) time_status |= STA_NANO; @@ -735,7 +733,7 @@ int __do_adjtimex(struct timex *txc, struct timespec64 *ts, s32 *time_tai) /* If there are input parameters, then process them: */ if (txc->modes) - process_adjtimex_modes(txc, ts, time_tai); + process_adjtimex_modes(txc, time_tai); txc->offset = shift_right(time_offset * NTP_INTERVAL_FREQ, NTP_SCALE_SHIFT); From patchwork Fri Jul 20 00:38:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 142390 Delivered-To: patches@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2346284ljj; Thu, 19 Jul 2018 17:38:57 -0700 (PDT) X-Received: by 2002:a62:a312:: with SMTP id s18-v6mr11495426pfe.13.1532047137273; Thu, 19 Jul 2018 17:38:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532047137; cv=none; d=google.com; s=arc-20160816; b=QvM3OFSWjWVUC1hvL878k4g4/u1RxIEVd+kG16s9mvOZwi4nFUUkKFgSEkKxVpzZN+ R8qyPAZvbNsn6hR4vs0igYOBvhXyoiMBuV+H9TOqBYQvODOWAWitnqcGMXEGdDoio96J ZSmaeOLVo1b3lMRux+DJeX3ID9bShS1xPEHkGZz0F3rAyWqf2sAuRf7x9093uBb7YaUh mKCMuiSzJfpIZlW8S0Sotb2Hzx0j+yaHyDVoFenA+Ii5NpI5CiOhDz3gJ6Xzn+r7opZT 9BHkpvOd9lZBKp7we0Ky02Aj5c7BUzDqjnyJ+3vOJfQS3NVnJUDqVkMFXJ1yUUtrvJlV R+Pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=EHPjg8dBQT3ytvd8eqbuqxN2QkOBzh0H7YT9D+lKcVU=; b=mYO0MbRj6d3E4HW0o2BiS7MvHLBfGDKF182pHhrL6WTxF4buUbgffcAHYG8K+egr8n AErmYWj3EQc1LdUWTSpHr9mS++GlkxoMiV4rc/B0VSWG95I5KU2qvpRsXdJEoBWiTHdb Uw7gMbxio9dsGWTcTFl0Ak0xXu4WkqR93LO+7rQmNS6bP0paEG5oG6b8w21WdHfqYhlF aG5rkb2GHkGrqxPD9vM7eXgLIVv3dNoanJJzo7Ok5wmr90AUSZtU1T6TwlhjBw5w400z b4+bhvVJI49gdqJYz/4yJZIR2hfvxMcxV4dBAd3vyfdEgNPd+bXt79uwPE7Izn+D9H5E AXmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OpYAudPi; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id h1-v6sor154774pgs.138.2018.07.19.17.38.57 for (Google Transport Security); Thu, 19 Jul 2018 17:38:57 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OpYAudPi; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=EHPjg8dBQT3ytvd8eqbuqxN2QkOBzh0H7YT9D+lKcVU=; b=OpYAudPiTdNtPt5Xh8MO3qtqNeEts+PmcyT5TrsDbZ8gFsGFEvYMb2XDfb4SKw9rFa R8q5tOnJt3bY2T/6L+kAWyP7XNkmQoJY6bmxd1xBwTd1wtCi5K2JYe7d1BFYI7suomtP FNAmP1kQFCQK3d+dK1fTl4HJxWLNUKoVMdAwE= 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=EHPjg8dBQT3ytvd8eqbuqxN2QkOBzh0H7YT9D+lKcVU=; b=sXuZCYWHlrt+zyopv6M1/lO1ciVErdpTxj//8m/fTGKxoovgxT+TE+h50tkB1aVq9o /FcXJ5xXJzINn1/cAebdqeop8MIm0xlY3nQhPzcDqz4guTcIi60r1v6sq20KOt+vLVcR gDJjE0UWdSvxqgxzpuIQitXenOsNSeK5Z5NG/s3cFwHw8C6btGBPlOENyvxAhtK53MHP nmub0HZB0E3WzNkWlwc6stWXs3oAdPbWV7ZPPUz2QrGSnsob9bTmjfau7TQD8VxpT/F+ BBDe2mkSUspft1bqu2L21Jytw5c+duc/JbUvy8UJiYzd9fz6zrCfFAK+1B49YFdwWK0D behg== X-Gm-Message-State: AOUpUlE6fLofN+T6ZcCqZ7C/Sr3VCCJWnZspTU1FJMfg93gRXTtv6+Vz CKsC+VYy/EaEMfeWsYsOMX+XWPps X-Google-Smtp-Source: AAOMgpciEaHOJycK6y0zv+vQNI4uqaz+feNKk/cSVg7Y5I1YmFM383/wFw768t+5Y8kU1MKyDsQejw== X-Received: by 2002:a65:6104:: with SMTP id z4-v6mr11992199pgu.361.1532047136761; Thu, 19 Jul 2018 17:38:56 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:600:5100:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id x5-v6sm383881pfh.67.2018.07.19.17.38.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Jul 2018 17:38:55 -0700 (PDT) From: John Stultz To: lkml Cc: Ondrej Mosnacek , Thomas Gleixner , Ingo Molnar , Miroslav Lichvar , Richard Cochran , Prarit Bhargava , Stephen Boyd , John Stultz Subject: [PATCH 2/5] ntp: Use kstrtos64 for s64 variable Date: Thu, 19 Jul 2018 17:38:44 -0700 Message-Id: <1532047127-26699-3-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1532047127-26699-1-git-send-email-john.stultz@linaro.org> References: <1532047127-26699-1-git-send-email-john.stultz@linaro.org> From: Ondrej Mosnacek ...instead of kstrtol with a dirty cast. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Miroslav Lichvar Cc: Richard Cochran Cc: Prarit Bhargava Cc: Stephen Boyd Signed-off-by: Ondrej Mosnacek Signed-off-by: John Stultz --- kernel/time/ntp.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) -- 2.7.4 diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 3eddac2..a627cae 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -1020,12 +1020,11 @@ void __hardpps(const struct timespec64 *phase_ts, const struct timespec64 *raw_t static int __init ntp_tick_adj_setup(char *str) { - int rc = kstrtol(str, 0, (long *)&ntp_tick_adj); - + int rc = kstrtos64(str, 0, &ntp_tick_adj); if (rc) return rc; - ntp_tick_adj <<= NTP_SCALE_SHIFT; + ntp_tick_adj <<= NTP_SCALE_SHIFT; return 1; } From patchwork Fri Jul 20 00:38:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 142391 Delivered-To: patches@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2346304ljj; Thu, 19 Jul 2018 17:38:59 -0700 (PDT) X-Received: by 2002:a63:4002:: with SMTP id n2-v6mr11662052pga.285.1532047139110; Thu, 19 Jul 2018 17:38:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532047139; cv=none; d=google.com; s=arc-20160816; b=aD/lY1psGXelDYL/o+snuPzgQ/oBmltzTeI4OadJl9MHAzS5OqRJ9++5BlXdCQ7IzN Sk89Hn7GvuZaF6J34cn9GjO0ETQzD5chipWIX5xBZL7fJ4hliD89R7VSXlJWJoTfoPN9 Dk0ABB8leSmrehVyiSf+hzaOhj8wzVjSJ+epc4xe4ura/JwTChkh80a1m3zB97IEnMA8 7QRR3vSoIEk6LtfwS7XdnrxVzbroPDIVWXbtr2PQntIKJoNQJz5FKAn/bJPPkxTGIEvm ahBZddRgDyks+LaKeAoQJvCPRkQbNYEVh6QdTKXjoi46+ggZvp3gzKOVGml6kO5urXD5 r4Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=PNbGX0T0xK8VL6GyXFrquqlsWfRX2fm1MYtj5XoLQh4=; b=DoycldHzd85YUA188IfOPpC5lc9tajjHFdM8iMdI6Z3zXmPYPCpHJqdHrWLpv5pHTm PVwnppiWk3JmfUnkmU4fYB4+svxwGTReAWM9SuBV+7UP7+1MJ1gve7wJ0w4IwBQDf7+1 TkTpBYQrILKoH3Ro1aBzFVsoqrbXBxFnIc8zu6LHSagwnaTaVkTapyBnHoEpbiR1eKU4 l+/pHHtERcccdGufLT//ZV9funa5UeAbCnpglvQSuSAroq7d6BKhfEQQsqZBjJQGCFvP ZeQPX61iaL3jjnN6co65+qF9FfnPOKgOnqWBNjHpkd8cxPvG+hNHvrGsDZrEjVFMfbMr C6mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HJ5o6R1J; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id g192-v6sor150151pfc.136.2018.07.19.17.38.58 for (Google Transport Security); Thu, 19 Jul 2018 17:38:59 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HJ5o6R1J; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=PNbGX0T0xK8VL6GyXFrquqlsWfRX2fm1MYtj5XoLQh4=; b=HJ5o6R1J6bwN6SAK7MGHRVvvrS8OTnyTj55kzK2nQhFtAYjaYowCIm9UkARksw9c5U y+z4VJJ2m89Zz6J0Ls+7vvkw176sU0RnHk/jw6Ic1QJP8nCyiqgQKG51HH+sReSaFcZJ sXRDRJBrSqK2aNJsCr2iwMrmKxEPMWhIGKw8w= 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=PNbGX0T0xK8VL6GyXFrquqlsWfRX2fm1MYtj5XoLQh4=; b=A3ksr22gm4XW7iqOH0QEBz6DJG06P0Re7XEyLjYHGG2Wgc6ncImm6/I/88uEV/f3c2 OVopnAlmUYgz9C4bqpnkEmkmDM453bqqS12QWHoSYxF6LN1LpNWDbPgOmoE4hZCos8eq lvnixOA4Vv1NIPoMo3EcFhqj7hrkl9vBKrMQMyTx5t29liP6xiHUn73Z6Q7xyAiMPZVN LOJNP6PyRqRm/c1C1pv9bjA9d8Gf5B3M+RitHAGXkFJ9RX9Zs/jS9BPaWue1mE+yWMFg J93J4s6aZ3Z0Sq3+UD2q81DNw7YlNyJDny0Z6Gp6qWez0671tayvyKGg9CDHcYJhD+sJ 23Yw== X-Gm-Message-State: AOUpUlGbbEjqbfesQVPiPojjPEgkZbmAjsVpc4kpYFwbsW1cLyLlDSXv semAfr+l140w+EoUZvYvCELU5Nip X-Google-Smtp-Source: AAOMgpetcfkCb0ih6izY6kE6h6XUJfPgfp3mdnQrYfw97mTQ6u0xozwz04GiUuV8CibFCpr4dWPJbw== X-Received: by 2002:a62:9b57:: with SMTP id r84-v6mr11582962pfd.6.1532047138553; Thu, 19 Jul 2018 17:38:58 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:600:5100:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id x5-v6sm383881pfh.67.2018.07.19.17.38.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Jul 2018 17:38:57 -0700 (PDT) From: John Stultz To: lkml Cc: Ondrej Mosnacek , Thomas Gleixner , Ingo Molnar , Miroslav Lichvar , Richard Cochran , Prarit Bhargava , Stephen Boyd , John Stultz Subject: [PATCH 3/5] timekeeping/ntp: Constify some function arguments Date: Thu, 19 Jul 2018 17:38:45 -0700 Message-Id: <1532047127-26699-4-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1532047127-26699-1-git-send-email-john.stultz@linaro.org> References: <1532047127-26699-1-git-send-email-john.stultz@linaro.org> From: Ondrej Mosnacek Add 'const' to some function arguments and variables to make it easier to read the code. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Miroslav Lichvar Cc: Richard Cochran Cc: Prarit Bhargava Cc: Stephen Boyd Signed-off-by: Ondrej Mosnacek [jstultz: Also fixup pre-existing checkpatch warnings for prototype arguments with no variable name] Signed-off-by: John Stultz --- include/linux/timekeeping.h | 2 +- kernel/time/ntp.c | 6 +++--- kernel/time/ntp_internal.h | 4 ++-- kernel/time/timekeeping.c | 29 +++++++++++++++-------------- kernel/time/timekeeping_debug.c | 2 +- kernel/time/timekeeping_internal.h | 2 +- 6 files changed, 23 insertions(+), 22 deletions(-) -- 2.7.4 diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index 86bc202..edace6b 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -177,7 +177,7 @@ static inline time64_t ktime_get_clocktai_seconds(void) extern bool timekeeping_rtc_skipsuspend(void); extern bool timekeeping_rtc_skipresume(void); -extern void timekeeping_inject_sleeptime64(struct timespec64 *delta); +extern void timekeeping_inject_sleeptime64(const struct timespec64 *delta); /* * struct system_time_snapshot - simultaneous raw/real time capture with diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index a627cae..c5e0cba 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -642,7 +642,7 @@ void ntp_notify_cmos_timer(void) /* * Propagate a new txc->status value into the NTP state: */ -static inline void process_adj_status(struct timex *txc) +static inline void process_adj_status(const struct timex *txc) { if ((time_status & STA_PLL) && !(txc->status & STA_PLL)) { time_state = TIME_OK; @@ -665,7 +665,7 @@ static inline void process_adj_status(struct timex *txc) } -static inline void process_adjtimex_modes(struct timex *txc, s32 *time_tai) +static inline void process_adjtimex_modes(const struct timex *txc, s32 *time_tai) { if (txc->modes & ADJ_STATUS) process_adj_status(txc); @@ -716,7 +716,7 @@ static inline void process_adjtimex_modes(struct timex *txc, s32 *time_tai) * adjtimex mainly allows reading (and writing, if superuser) of * kernel time-keeping variables. used by xntpd. */ -int __do_adjtimex(struct timex *txc, struct timespec64 *ts, s32 *time_tai) +int __do_adjtimex(struct timex *txc, const struct timespec64 *ts, s32 *time_tai) { int result; diff --git a/kernel/time/ntp_internal.h b/kernel/time/ntp_internal.h index 909bd1f..c24b0e1 100644 --- a/kernel/time/ntp_internal.h +++ b/kernel/time/ntp_internal.h @@ -8,6 +8,6 @@ extern void ntp_clear(void); extern u64 ntp_tick_length(void); extern ktime_t ntp_get_next_leap(void); extern int second_overflow(time64_t secs); -extern int __do_adjtimex(struct timex *, struct timespec64 *, s32 *); -extern void __hardpps(const struct timespec64 *, const struct timespec64 *); +extern int __do_adjtimex(struct timex *txc, const struct timespec64 *ts, s32 *time_tai); +extern void __hardpps(const struct timespec64 *phase_ts, const struct timespec64 *raw_ts); #endif /* _LINUX_NTP_INTERNAL_H */ diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index ad779c2..7033ac1 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -105,7 +105,7 @@ static inline void tk_normalize_xtime(struct timekeeper *tk) } } -static inline struct timespec64 tk_xtime(struct timekeeper *tk) +static inline struct timespec64 tk_xtime(const struct timekeeper *tk) { struct timespec64 ts; @@ -162,7 +162,7 @@ static inline void tk_update_sleep_time(struct timekeeper *tk, ktime_t delta) * a read of the fast-timekeeper tkrs (which is protected by its own locking * and update logic). */ -static inline u64 tk_clock_read(struct tk_read_base *tkr) +static inline u64 tk_clock_read(const struct tk_read_base *tkr) { struct clocksource *clock = READ_ONCE(tkr->clock); @@ -211,7 +211,7 @@ static void timekeeping_check_update(struct timekeeper *tk, u64 offset) } } -static inline u64 timekeeping_get_delta(struct tk_read_base *tkr) +static inline u64 timekeeping_get_delta(const struct tk_read_base *tkr) { struct timekeeper *tk = &tk_core.timekeeper; u64 now, last, mask, max, delta; @@ -255,7 +255,7 @@ static inline u64 timekeeping_get_delta(struct tk_read_base *tkr) static inline void timekeeping_check_update(struct timekeeper *tk, u64 offset) { } -static inline u64 timekeeping_get_delta(struct tk_read_base *tkr) +static inline u64 timekeeping_get_delta(const struct tk_read_base *tkr) { u64 cycle_now, delta; @@ -352,7 +352,7 @@ u32 (*arch_gettimeoffset)(void) = default_arch_gettimeoffset; static inline u32 arch_gettimeoffset(void) { return 0; } #endif -static inline u64 timekeeping_delta_to_ns(struct tk_read_base *tkr, u64 delta) +static inline u64 timekeeping_delta_to_ns(const struct tk_read_base *tkr, u64 delta) { u64 nsec; @@ -363,7 +363,7 @@ static inline u64 timekeeping_delta_to_ns(struct tk_read_base *tkr, u64 delta) return nsec + arch_gettimeoffset(); } -static inline u64 timekeeping_get_ns(struct tk_read_base *tkr) +static inline u64 timekeeping_get_ns(const struct tk_read_base *tkr) { u64 delta; @@ -371,7 +371,7 @@ static inline u64 timekeeping_get_ns(struct tk_read_base *tkr) return timekeeping_delta_to_ns(tkr, delta); } -static inline u64 timekeeping_cycles_to_ns(struct tk_read_base *tkr, u64 cycles) +static inline u64 timekeeping_cycles_to_ns(const struct tk_read_base *tkr, u64 cycles) { u64 delta; @@ -394,7 +394,8 @@ static inline u64 timekeeping_cycles_to_ns(struct tk_read_base *tkr, u64 cycles) * slightly wrong timestamp (a few nanoseconds). See * @ktime_get_mono_fast_ns. */ -static void update_fast_timekeeper(struct tk_read_base *tkr, struct tk_fast *tkf) +static void update_fast_timekeeper(const struct tk_read_base *tkr, + struct tk_fast *tkf) { struct tk_read_base *base = tkf->base; @@ -549,10 +550,10 @@ EXPORT_SYMBOL_GPL(ktime_get_real_fast_ns); * number of cycles every time until timekeeping is resumed at which time the * proper readout base for the fast timekeeper will be restored automatically. */ -static void halt_fast_timekeeper(struct timekeeper *tk) +static void halt_fast_timekeeper(const struct timekeeper *tk) { static struct tk_read_base tkr_dummy; - struct tk_read_base *tkr = &tk->tkr_mono; + const struct tk_read_base *tkr = &tk->tkr_mono; memcpy(&tkr_dummy, tkr, sizeof(tkr_dummy)); cycles_at_suspend = tk_clock_read(tkr); @@ -1277,7 +1278,7 @@ EXPORT_SYMBOL(do_settimeofday64); * * Adds or subtracts an offset value from the current time. */ -static int timekeeping_inject_offset(struct timespec64 *ts) +static int timekeeping_inject_offset(const struct timespec64 *ts) { struct timekeeper *tk = &tk_core.timekeeper; unsigned long flags; @@ -1585,7 +1586,7 @@ static struct timespec64 timekeeping_suspend_time; * adds the sleep offset to the timekeeping variables. */ static void __timekeeping_inject_sleeptime(struct timekeeper *tk, - struct timespec64 *delta) + const struct timespec64 *delta) { if (!timespec64_valid_strict(delta)) { printk_deferred(KERN_WARNING @@ -1646,7 +1647,7 @@ bool timekeeping_rtc_skipsuspend(void) * This function should only be called by rtc_resume(), and allows * a suspend offset to be injected into the timekeeping values. */ -void timekeeping_inject_sleeptime64(struct timespec64 *delta) +void timekeeping_inject_sleeptime64(const struct timespec64 *delta) { struct timekeeper *tk = &tk_core.timekeeper; unsigned long flags; @@ -2240,7 +2241,7 @@ ktime_t ktime_get_update_offsets_now(unsigned int *cwsseq, ktime_t *offs_real, /** * timekeeping_validate_timex - Ensures the timex is ok for use in do_adjtimex */ -static int timekeeping_validate_timex(struct timex *txc) +static int timekeeping_validate_timex(const struct timex *txc) { if (txc->modes & ADJ_ADJTIME) { /* singleshot must not be used with any other mode bits */ diff --git a/kernel/time/timekeeping_debug.c b/kernel/time/timekeeping_debug.c index 0754cad..238e4be 100644 --- a/kernel/time/timekeeping_debug.c +++ b/kernel/time/timekeeping_debug.c @@ -70,7 +70,7 @@ static int __init tk_debug_sleep_time_init(void) } late_initcall(tk_debug_sleep_time_init); -void tk_debug_account_sleep_time(struct timespec64 *t) +void tk_debug_account_sleep_time(const struct timespec64 *t) { /* Cap bin index so we don't overflow the array */ int bin = min(fls(t->tv_sec), NUM_BINS-1); diff --git a/kernel/time/timekeeping_internal.h b/kernel/time/timekeeping_internal.h index cf5c082..bcbb52d 100644 --- a/kernel/time/timekeeping_internal.h +++ b/kernel/time/timekeeping_internal.h @@ -8,7 +8,7 @@ #include #ifdef CONFIG_DEBUG_FS -extern void tk_debug_account_sleep_time(struct timespec64 *t); +extern void tk_debug_account_sleep_time(const struct timespec64 *t); #else #define tk_debug_account_sleep_time(x) #endif From patchwork Fri Jul 20 00:38:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 142392 Delivered-To: patches@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2346336ljj; Thu, 19 Jul 2018 17:39:00 -0700 (PDT) X-Received: by 2002:a17:902:1101:: with SMTP id d1-v6mr11937065pla.147.1532047140796; Thu, 19 Jul 2018 17:39:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532047140; cv=none; d=google.com; s=arc-20160816; b=kkKNH7JpQOz8iRpvfMSXBTSHmkqGW7TBX5VQPMtW22aMVsRaSEFWAVJsjO5gwMS/QY 3jxFxZXH33tjyjUVaknsiSln4lQdW46XmCMGTERLckwbo4cgjr2dNPuiC7ho74A2xBXZ Ftw2788lHphEztIiPTQITYPFOB+4p5wnpIPhXqlH2WVYmxvWCnfuBbYhsUKZa0Rlu4lT HfJEM2rRG6Lfc1syGGwiYdmIroEualllqvYz2BpmzjSnRTW+QXnMy3k5Dt25e6Qo70N9 xsthKI+sE1MvhDyYOBjGuH/LLtiuN+NyCBZuo4qPVmStxtlYnKbBrcrcEjomc3FnWMAV LDYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=cl8QC7cI0N14M5eI441ZKx5bQCWuSElbitp4+Wv2+PI=; b=UYHMtsTR32r1wB5vYiInfcxs7oOCG4WLlWNYggsJjUmWtBiXbRqQnG5HhBgodTIq4G G0M1h7U2acmmI9Q4T07gSjGVcESg2m+LkYMelB/sLb11+TUpOjXmTBIazLbP3mFc3Nt/ GCme6vx/mT+CBZVe+wgYZPcGj1l5hyWJE7r4zue40BD5KTHTtb+7QE/+9ZiFJHVx50O/ Avl1u0jPJBIFHB++gYc8lbnsGznjEZSydOfI9kQvVXCcY5TQkqNqu2KiiuUD7uRZCiAH n52PqLDBX8iMANo5Lbv6VrYVuXMlWuTVtPTc9XfuQgrxS/5dnZwsSysJMWtoA+Ug93hU G9Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kZa21Kgl; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id 67-v6sor153382pfn.82.2018.07.19.17.39.00 for (Google Transport Security); Thu, 19 Jul 2018 17:39:00 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kZa21Kgl; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=cl8QC7cI0N14M5eI441ZKx5bQCWuSElbitp4+Wv2+PI=; b=kZa21KglaWxEqM0xlsSMhBsjKtDHjIsjIc/dubcPVir2DW9U8llDy+eAreRtz+VPh+ cWqO76umVmOZFcOntsn9yeFCXsieBUOlICtJmqyK4xT1B3x8JL9CdZ1wZMtvebl3ocmh nno1CBnc/UsIQhPmKYV654C4AWkvueafBp0mA= 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=cl8QC7cI0N14M5eI441ZKx5bQCWuSElbitp4+Wv2+PI=; b=bHDogBejyUwGVwzGr2tZEf55vYRzneRYSSkZ3V51WyAGxvxP+Ax4a8xmPvrEXEkNHi R4zXpXhfr+T8v13L469vrr+4E/opASXkCUvZezFh3UQapNZ/923dJD+X5/ds1SFntuIJ kVj326E5LmWaiv/cqKR/82dAxbOVXLe/LJJzY2HttG26UF82i3xnTMOyH6vKz7LUamQl 60JQtGq5UEWdFGlOxddelTdM2jjNEB/cGbuEUWWA7yU8AST6ryjVz0M+prWG+xxMPlPq /U4jA+mw5I59STN8yUcD2kazHBbFVs6rbFCcrA/9/G35O9OTDfU4p3O2srRFAzmkTWs4 qMfw== X-Gm-Message-State: AOUpUlFftqCjR+ryWa7KlQ6BS2/9ht+OYNpRdQMVMaN6gthHwr80Y2P7 0EsI6Cs5wl40IAch74fjm+WsxXqUJgzROw== X-Google-Smtp-Source: AAOMgpdZMCHoelfAac2uKmtq5tf76cMfbWlEC4ja5MThwTlFypp2jexX82UyVQu999XmIONGF03Dqw== X-Received: by 2002:a62:864a:: with SMTP id x71-v6mr11744256pfd.252.1532047140290; Thu, 19 Jul 2018 17:39:00 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:600:5100:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id x5-v6sm383881pfh.67.2018.07.19.17.38.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Jul 2018 17:38:59 -0700 (PDT) From: John Stultz To: lkml Cc: Mukesh Ojha , Thomas Gleixner , Ingo Molnar , Miroslav Lichvar , Richard Cochran , Prarit Bhargava , Stephen Boyd , John Stultz Subject: [PATCH 4/5] time: Fix extra sleeptime injection when suspend fails Date: Thu, 19 Jul 2018 17:38:46 -0700 Message-Id: <1532047127-26699-5-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1532047127-26699-1-git-send-email-john.stultz@linaro.org> References: <1532047127-26699-1-git-send-email-john.stultz@linaro.org> From: Mukesh Ojha Currently, there exists a corner case assuming when there is only one clocksource e.g RTC, and system failed to go to suspend mode. While resume rtc_resume() injects the sleeptime as timekeeping_rtc_skipresume() returned 'false' (default value of sleeptime_injected) due to which we can see mismatch in timestamps. This issue can also come in a system where more than one clocksource are present and very first suspend fails. Success case: ------------ {sleeptime_injected=false} rtc_suspend() => timekeeping_suspend() => timekeeping_resume() => (sleeptime injected) rtc_resume() Failure case: ------------ {failure in sleep path} {sleeptime_injected=false} rtc_suspend() => rtc_resume() {sleeptime injected again which was not required as the suspend failed} Fix this by handling the boolean logic properly. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Miroslav Lichvar Cc: Richard Cochran Cc: Prarit Bhargava Cc: Stephen Boyd Originally-by: Thomas Gleixner Signed-off-by: Mukesh Ojha Signed-off-by: John Stultz --- kernel/time/timekeeping.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) -- 2.7.4 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 7033ac1..19414b1 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1519,8 +1519,20 @@ void __weak read_boot_clock64(struct timespec64 *ts) ts->tv_nsec = 0; } -/* Flag for if timekeeping_resume() has injected sleeptime */ -static bool sleeptime_injected; +/* + * Flag reflecting whether timekeeping_resume() has injected sleeptime. + * + * The flag starts of false and is only set when a suspend reaches + * timekeeping_suspend(), timekeeping_resume() sets it to false when the + * timekeeper clocksource is not stopping across suspend and has been + * used to update sleep time. If the timekeeper clocksource has stopped + * then the flag stays true and is used by the RTC resume code to decide + * whether sleeptime must be injected and if so the flag gets false then. + * + * If a suspend fails before reaching timekeeping_resume() then the flag + * stays false and prevents erroneous sleeptime injection. + */ +static bool suspend_timing_needed; /* Flag for if there is a persistent clock on this platform */ static bool persistent_clock_exists; @@ -1619,7 +1631,7 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk, */ bool timekeeping_rtc_skipresume(void) { - return sleeptime_injected; + return !suspend_timing_needed; } /** @@ -1655,6 +1667,8 @@ void timekeeping_inject_sleeptime64(const struct timespec64 *delta) raw_spin_lock_irqsave(&timekeeper_lock, flags); write_seqcount_begin(&tk_core.seq); + suspend_timing_needed = false; + timekeeping_forward_now(tk); __timekeeping_inject_sleeptime(tk, delta); @@ -1679,8 +1693,8 @@ void timekeeping_resume(void) unsigned long flags; struct timespec64 ts_new, ts_delta; u64 cycle_now; + bool inject_sleeptime = false; - sleeptime_injected = false; read_persistent_clock64(&ts_new); clockevents_resume(); @@ -1710,14 +1724,16 @@ void timekeeping_resume(void) tk->tkr_mono.mask); nsec = mul_u64_u32_shr(cyc_delta, clock->mult, clock->shift); ts_delta = ns_to_timespec64(nsec); - sleeptime_injected = true; + inject_sleeptime = true; } else if (timespec64_compare(&ts_new, &timekeeping_suspend_time) > 0) { ts_delta = timespec64_sub(ts_new, timekeeping_suspend_time); - sleeptime_injected = true; + inject_sleeptime = true; } - if (sleeptime_injected) + if (inject_sleeptime) { + suspend_timing_needed = false; __timekeeping_inject_sleeptime(tk, &ts_delta); + } /* Re-base the last cycle value */ tk->tkr_mono.cycle_last = cycle_now; @@ -1752,6 +1768,8 @@ int timekeeping_suspend(void) if (timekeeping_suspend_time.tv_sec || timekeeping_suspend_time.tv_nsec) persistent_clock_exists = true; + suspend_timing_needed = true; + raw_spin_lock_irqsave(&timekeeper_lock, flags); write_seqcount_begin(&tk_core.seq); timekeeping_forward_now(tk); From patchwork Fri Jul 20 00:38:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 142393 Delivered-To: patches@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2346377ljj; Thu, 19 Jul 2018 17:39:03 -0700 (PDT) X-Received: by 2002:a17:902:b604:: with SMTP id b4-v6mr12090265pls.18.1532047142905; Thu, 19 Jul 2018 17:39:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532047142; cv=none; d=google.com; s=arc-20160816; b=kIa5Q2zRIjP9fZVL+5hvrbOE6X2PmlLqeroZvR7OYbbxETGm8IdQXmEJ0pZ7eJ4OSU 0P6wmVBrJhsckuaTq7bBuJuYAjNH+vr5+N2BIQK4afZVWstFYao+qbFsALOBrwvDfojO wYbmG+1PZqrGa6fxPcIqFH7Sv0wJona8R7aexwsGNgWhFOzDm9+IfVTI2vHadP/vWzVU Y37BS3JQhPKYnX/Kq9bAJ3Qin5dI6Fz6ENLana/Tpb3+Xruyi530TNgBAAx7tGAPoyRJ zG3Zswy4S1RDYyWUIKc8FEp8LayLo3K3xLh/L6QjajVYcRlEipQ4wGkUBHpkQSKgo+h6 mn9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=A5O6CNHrb0qDdU0p+2FJ9R3kj4+jXVvKqMufBr+D4Lo=; b=iKS9jXP/60RQnH9rhzHjEnmJJVjwE6TqXbxdNa6R+c3rgrUBkCgB/RAtjaTxn4TGD4 6n61SqbKI/7dWivU8lP9vdsWwOz0wpdy/Biuvf2K1uuQPoyjzkxaWvYbM+WdTEYpgw4I oAFTO4SQEIJpi0qyQI2fKVVwVAG7yvMkrkeIf1oQCDVIhlVVgxiKvH5SEksmPt/PLrcQ BFJd9HK9uLzyd6G2+U5qaJfRwHWl9NbC/I0TqcPf5j+rDVRp0JUUEWIGhK9MlkSZC1bY tCg/U7zS1LZTayjulu6FY7dvdK+EkV691VlP1ojXOUy7/pg3LitY2V7ksTpZzPh3xOCA GcIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="YCN/n84F"; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id k3-v6sor150367pgi.304.2018.07.19.17.39.02 for (Google Transport Security); Thu, 19 Jul 2018 17:39:02 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="YCN/n84F"; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=A5O6CNHrb0qDdU0p+2FJ9R3kj4+jXVvKqMufBr+D4Lo=; b=YCN/n84F1/Gr7GNXs0cnPwBjfBORmP1eUZZ5FAwJiwqw6EMA7Il5G3BeBzLIIuGxK7 nMMprosvg3g8WZLABvW42pM6g41Sj7pQgpNIRQL8q3DYvxfDYAEoE94k2ROTTqYheNyZ X8yeIaf698VkbJYcnaBQMCi8fYDe6oOs/7oeA= 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=A5O6CNHrb0qDdU0p+2FJ9R3kj4+jXVvKqMufBr+D4Lo=; b=jJwc1C7p8j6nhnqAJlHocxQ7GK580mlRnpzngVyMV6TdBjc4m2W1KoAGNo3IkmzXiO p9826Qow0maSHsu8M6jNC5J5COahq4WpTSMZFALh4KoTYO9k7sLODPeYgzpO9Vg4I39d bbTuZWVWu5cnBJXjVKoalMbAik6WgbTIuMHcekAwk6VISCEnQTjZki7uR/ditEFddc+e U0Jf46KUGJpOVcXl2HzgDiFINfo9LulKSZrYKmrIoWA0j8n2SVcK48u1SCE9CXINOYoV eY43RsL3EK8apdYi92/nhJv5zbH7RgfwF0lsxnrGGEVQ6uuGfFLaW0GJc2zVMw7oMRbO NzVg== X-Gm-Message-State: AOUpUlGgxkJ73UWPxBiGT4oQj3E2hqKp2ST17cn9yk5wYWHu9ecX62UC X1TrudMnBk6F8fvT6pLzPlxOEZUk X-Google-Smtp-Source: AAOMgpeJTLFSn56lyzi0gmzKKT40rdnvcgDZwin5pmwmnfEPtqkhhwTfAdhZmwUjeu4JisEyaZLCjg== X-Received: by 2002:a63:2c8e:: with SMTP id s136-v6mr11650102pgs.390.1532047142351; Thu, 19 Jul 2018 17:39:02 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:600:5100:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id x5-v6sm383881pfh.67.2018.07.19.17.39.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Jul 2018 17:39:01 -0700 (PDT) From: John Stultz To: lkml Cc: Baolin Wang , Thomas Gleixner , Ingo Molnar , Miroslav Lichvar , Richard Cochran , Prarit Bhargava , Stephen Boyd , Daniel Lezcano , John Stultz Subject: [PATCH 5/5] time: Introduce one suspend clocksource to compensate the suspend time Date: Thu, 19 Jul 2018 17:38:47 -0700 Message-Id: <1532047127-26699-6-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1532047127-26699-1-git-send-email-john.stultz@linaro.org> References: <1532047127-26699-1-git-send-email-john.stultz@linaro.org> From: Baolin Wang On some hardware with multiple clocksources, we have coarse grained clocksources that support the CLOCK_SOURCE_SUSPEND_NONSTOP flag, but which are less than ideal for timekeeping whereas other clocksources can be better candidates but halt on suspend. Currently, the timekeeping core only supports timing suspend using CLOCK_SOURCE_SUSPEND_NONSTOP clocksources if that clocksource is the current clocksource for timekeeping. As a result, some architectures try to implement read_persistent_clock64() using those non-stop clocksources, but isn't really ideal, which will introduce more duplicate code. To fix this, provide logic to allow a registered SUSPEND_NONSTOP clocksource, which isn't the current clocksource, to be used to calculate the suspend time. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Miroslav Lichvar Cc: Richard Cochran Cc: Prarit Bhargava Cc: Stephen Boyd Cc: Daniel Lezcano Reviewed-by: Thomas Gleixner Reviewed-by: Daniel Lezcano Suggested-by: Thomas Gleixner Signed-off-by: Baolin Wang [jstultz: minor tweaks to merge with previous resume changes] Signed-off-by: John Stultz --- include/linux/clocksource.h | 3 + kernel/time/clocksource.c | 149 ++++++++++++++++++++++++++++++++++++++++++++ kernel/time/timekeeping.c | 22 ++++--- 3 files changed, 166 insertions(+), 8 deletions(-) -- 2.7.4 diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h index 7dff196..3089189 100644 --- a/include/linux/clocksource.h +++ b/include/linux/clocksource.h @@ -194,6 +194,9 @@ extern void clocksource_suspend(void); extern void clocksource_resume(void); extern struct clocksource * __init clocksource_default_clock(void); extern void clocksource_mark_unstable(struct clocksource *cs); +extern void +clocksource_start_suspend_timing(struct clocksource *cs, u64 start_cycles); +extern u64 clocksource_stop_suspend_timing(struct clocksource *cs, u64 now); extern u64 clocks_calc_max_nsecs(u32 mult, u32 shift, u32 maxadj, u64 mask, u64 *max_cycles); diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c index f89a78e..f74fb00 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c @@ -94,6 +94,8 @@ EXPORT_SYMBOL_GPL(clocks_calc_mult_shift); /*[Clocksource internal variables]--------- * curr_clocksource: * currently selected clocksource. + * suspend_clocksource: + * used to calculate the suspend time. * clocksource_list: * linked list with the registered clocksources * clocksource_mutex: @@ -102,10 +104,12 @@ EXPORT_SYMBOL_GPL(clocks_calc_mult_shift); * Name of the user-specified clocksource. */ static struct clocksource *curr_clocksource; +static struct clocksource *suspend_clocksource; static LIST_HEAD(clocksource_list); static DEFINE_MUTEX(clocksource_mutex); static char override_name[CS_NAME_LEN]; static int finished_booting; +static u64 suspend_start; #ifdef CONFIG_CLOCKSOURCE_WATCHDOG static void clocksource_watchdog_work(struct work_struct *work); @@ -447,6 +451,140 @@ static inline void clocksource_watchdog_unlock(unsigned long *flags) { } #endif /* CONFIG_CLOCKSOURCE_WATCHDOG */ +static bool clocksource_is_suspend(struct clocksource *cs) +{ + return cs == suspend_clocksource; +} + +static void __clocksource_suspend_select(struct clocksource *cs) +{ + /* + * Skip the clocksource which will be stopped in suspend state. + */ + if (!(cs->flags & CLOCK_SOURCE_SUSPEND_NONSTOP)) + return; + + /* + * The nonstop clocksource can be selected as the suspend clocksource to + * calculate the suspend time, so it should not supply suspend/resume + * interfaces to suspend the nonstop clocksource when system suspends. + */ + if (cs->suspend || cs->resume) { + pr_warn("Nonstop clocksource %s should not supply suspend/resume interfaces\n", + cs->name); + } + + /* Pick the best rating. */ + if (!suspend_clocksource || cs->rating > suspend_clocksource->rating) + suspend_clocksource = cs; +} + +/** + * clocksource_suspend_select - Select the best clocksource for suspend timing + * @fallback: if select a fallback clocksource + */ +static void clocksource_suspend_select(bool fallback) +{ + struct clocksource *cs, *old_suspend; + + old_suspend = suspend_clocksource; + if (fallback) + suspend_clocksource = NULL; + + list_for_each_entry(cs, &clocksource_list, list) { + /* Skip current if we were requested for a fallback. */ + if (fallback && cs == old_suspend) + continue; + + __clocksource_suspend_select(cs); + } +} + +/** + * clocksource_start_suspend_timing - Start measuring the suspend timing + * @cs: current clocksource from timekeeping + * @start_cycles: current cycles from timekeeping + * + * This function will save the start cycle values of suspend timer to calculate + * the suspend time when resuming system. + * + * This function is called late in the suspend process from timekeeping_suspend(), + * that means processes are freezed, non-boot cpus and interrupts are disabled + * now. It is therefore possible to start the suspend timer without taking the + * clocksource mutex. + */ +void clocksource_start_suspend_timing(struct clocksource *cs, u64 start_cycles) +{ + if (!suspend_clocksource) + return; + + /* + * If current clocksource is the suspend timer, we should use the + * tkr_mono.cycle_last value as suspend_start to avoid same reading + * from suspend timer. + */ + if (clocksource_is_suspend(cs)) { + suspend_start = start_cycles; + return; + } + + if (suspend_clocksource->enable && + suspend_clocksource->enable(suspend_clocksource)) { + pr_warn_once("Failed to enable the non-suspend-able clocksource.\n"); + return; + } + + suspend_start = suspend_clocksource->read(suspend_clocksource); +} + +/** + * clocksource_stop_suspend_timing - Stop measuring the suspend timing + * @cs: current clocksource from timekeeping + * @cycle_now: current cycles from timekeeping + * + * This function will calculate the suspend time from suspend timer. + * + * Returns nanoseconds since suspend started, 0 if no usable suspend clocksource. + * + * This function is called early in the resume process from timekeeping_resume(), + * that means there is only one cpu, no processes are running and the interrupts + * are disabled. It is therefore possible to stop the suspend timer without + * taking the clocksource mutex. + */ +u64 clocksource_stop_suspend_timing(struct clocksource *cs, u64 cycle_now) +{ + u64 now, delta, nsec = 0; + + if (!suspend_clocksource) + return 0; + + /* + * If current clocksource is the suspend timer, we should use the + * tkr_mono.cycle_last value from timekeeping as current cycle to + * avoid same reading from suspend timer. + */ + if (clocksource_is_suspend(cs)) + now = cycle_now; + else + now = suspend_clocksource->read(suspend_clocksource); + + if (now > suspend_start) { + delta = clocksource_delta(now, suspend_start, + suspend_clocksource->mask); + nsec = mul_u64_u32_shr(delta, suspend_clocksource->mult, + suspend_clocksource->shift); + } + + /* + * Disable the suspend timer to save power if current clocksource is + * not the suspend timer. + */ + if (!clocksource_is_suspend(cs) && suspend_clocksource->disable) + suspend_clocksource->disable(suspend_clocksource); + + return nsec; +} + /** * clocksource_suspend - suspend the clocksource(s) */ @@ -792,6 +930,7 @@ int __clocksource_register_scale(struct clocksource *cs, u32 scale, u32 freq) clocksource_select(); clocksource_select_watchdog(false); + __clocksource_suspend_select(cs); mutex_unlock(&clocksource_mutex); return 0; } @@ -820,6 +959,7 @@ void clocksource_change_rating(struct clocksource *cs, int rating) clocksource_select(); clocksource_select_watchdog(false); + clocksource_suspend_select(false); mutex_unlock(&clocksource_mutex); } EXPORT_SYMBOL(clocksource_change_rating); @@ -845,6 +985,15 @@ static int clocksource_unbind(struct clocksource *cs) return -EBUSY; } + if (clocksource_is_suspend(cs)) { + /* + * Select and try to install a replacement suspend clocksource. + * If no replacement suspend clocksource, we will just let the + * clocksource go and have no suspend clocksource. + */ + clocksource_suspend_select(true); + } + clocksource_watchdog_lock(&flags); clocksource_dequeue_watchdog(cs); list_del_init(&cs->list); diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 19414b1..d9e659a 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1692,7 +1692,7 @@ void timekeeping_resume(void) struct clocksource *clock = tk->tkr_mono.clock; unsigned long flags; struct timespec64 ts_new, ts_delta; - u64 cycle_now; + u64 cycle_now, nsec; bool inject_sleeptime = false; read_persistent_clock64(&ts_new); @@ -1716,13 +1716,8 @@ void timekeeping_resume(void) * usable source. The rtc part is handled separately in rtc core code. */ cycle_now = tk_clock_read(&tk->tkr_mono); - if ((clock->flags & CLOCK_SOURCE_SUSPEND_NONSTOP) && - cycle_now > tk->tkr_mono.cycle_last) { - u64 nsec, cyc_delta; - - cyc_delta = clocksource_delta(cycle_now, tk->tkr_mono.cycle_last, - tk->tkr_mono.mask); - nsec = mul_u64_u32_shr(cyc_delta, clock->mult, clock->shift); + nsec = clocksource_stop_suspend_timing(clock, cycle_now); + if (nsec > 0) { ts_delta = ns_to_timespec64(nsec); inject_sleeptime = true; } else if (timespec64_compare(&ts_new, &timekeeping_suspend_time) > 0) { @@ -1757,6 +1752,8 @@ int timekeeping_suspend(void) unsigned long flags; struct timespec64 delta, delta_delta; static struct timespec64 old_delta; + struct clocksource *curr_clock; + u64 cycle_now; read_persistent_clock64(&timekeeping_suspend_time); @@ -1775,6 +1772,15 @@ int timekeeping_suspend(void) timekeeping_forward_now(tk); timekeeping_suspended = 1; + /* + * Since we've called forward_now, cycle_last stores the value + * just read from the current clocksource. Save this to potentially + * use in suspend timing. + */ + curr_clock = tk->tkr_mono.clock; + cycle_now = tk->tkr_mono.cycle_last; + clocksource_start_suspend_timing(curr_clock, cycle_now); + if (persistent_clock_exists) { /* * To avoid drift caused by repeated suspend/resumes,