From patchwork Tue Jan 16 17:01:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 124749 Delivered-To: patch@linaro.org Received: by 10.46.64.148 with SMTP id r20csp1080399lje; Tue, 16 Jan 2018 09:02:37 -0800 (PST) X-Google-Smtp-Source: ACJfBotQ5d+Oxl+z5PdMFDsy5QDQYWFBWlA/U8CK5J79pGeIKbniuEqBGdVhtitfn8j2qpYvXnle X-Received: by 10.99.129.199 with SMTP id t190mr8445828pgd.120.1516122157713; Tue, 16 Jan 2018 09:02:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516122157; cv=none; d=google.com; s=arc-20160816; b=QC3vQv6s6CIMCWCHa8uMtKOcWvViV0feMQ9Uesqff4Pzpb6N09IclEIZE1JInd/QT/ yn+r1gTenmb47hHwt+NEC7CCYGHKWzqU0QTb4IaO9kEQA2j8ylUqEOlIQ6athGDxOVNl NQj3wW/ebUFDDQCw6amrsxdHvv2tKPeDHgMgp2H5uxzoHXzwmm53Cm4OTvlC+MtbNvqf mZr0t6l/yI/AzMYw4/9JxWAemEGLNt4/s+UlfvD2ohm12NZuRZnCYG/jzL8bUJyHrxd3 n3Krk84kLFpGKP81T2uA1We2HowZ2Ipn53CrzsMhdMNKIH18YLsWUtRDgIV4tiPjOcpa 2Npw== 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 :arc-authentication-results; bh=C8x0Ue5SFmXUi/RBbAvcLDs2Bukz7UbZLGMgBQgDNms=; b=KEQ/VBB/9jJFAT+HMSfOPgeqrVk9T2GLp7XtsHjPvO4qLqVMZxkyCZUsKx+BFAF4y3 d1xb1WZVAW40kVLJh1X4TQ9n4pH3IaILRKUzAtxt9QyTS/gg68FgwlEitDVFYJ8pQI3j GpbKTCx3SR2XrxSBr5s/bb2iM3AKtoZrxHOZPjPX7vK9HpEIlseuozza/nEWV16SFRFv HImyUZBmfRqMnkGrZetmKhWB81Gw4OWnrB4iDmMliNg9lDMybP1CfRVMpjdClyKr8PzB HPwlRxaQAI7QzOlThEpB6N4o4vNIsRKfeuzmxJ8FavHDqq/yZk1zrIWVKY1tQ+IgPnNA XQxw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v11si1949571pgf.326.2018.01.16.09.02.37; Tue, 16 Jan 2018 09:02:37 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751325AbeAPRCf (ORCPT + 28 others); Tue, 16 Jan 2018 12:02:35 -0500 Received: from mout.kundenserver.de ([212.227.17.24]:60051 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750823AbeAPRCe (ORCPT ); Tue, 16 Jan 2018 12:02:34 -0500 Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.145]) with ESMTPA (Nemesis) id 0MK26P-1eafoQ0msn-001Tdm; Tue, 16 Jan 2018 18:02:23 +0100 From: Arnd Bergmann To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Arnd Bergmann , Tyrel Datwyler , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH] [RESEND] powerpc: mpic_timer: avoid struct timeval Date: Tue, 16 Jan 2018 18:01:50 +0100 Message-Id: <20180116170220.2598520-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:TqfHjXD6jg2nB3rJLo19mQUVUqo92WO4cPL6qfBJ0EtipsExoa0 IdvL624bMj2Dt2nX12aW65r8rE/vnTMqJ6R9rWvQDsPdsUTvKLLyDDUSqq2134kCN4DhIfB VXUIVCMnTTjYDomKPy4VqiGL2G59dTpgRXcB2w+dg3jFaLDD0OYw4IHKTIiBD70QL81OZa1 qZ3N8cHjiVZitB8vGFh1g== X-UI-Out-Filterresults: notjunk:1; V01:K0:svcn+1A54xw=:EYXIZRIrfxqSadj7tdxmke 7seq8WGAX1vdFJvPj3iGJzkwzIHnr5+ljmj11BuRbIyArvSQ7WXUAhPlqR8uw9AnZ7ZuJITii S6H9+atro4dk+wIJFbexADYEn5KziMRPbRs2c1FHRI/Tg19PT/V3SbczBT6OzmdG+zyjjrQqs YrK840kk92B49YzV0mCJRl/nIaWdpeRIli8Pd53+y9ip6gPipjWAhGthH8G+/PirjuEx1UNIx R1/BZIcKixpdlJ+7Zb9X18q2micaTVLME8JdXywJcaAcgXN5Mm/QNiaj0cEqTkSv2KQegKg74 qtYh9fqfBlrrGWlxCfkYXkHumROnyc42XYQXZFp0svKks/BMeLyduplMpiRGjPd1+6Z4UFlXy Racf/rTGRoEGX2t/c7FfBhvykMRJAnfQDTIOsV0hlAj5m/mg6V7cJdDmr/yD7PgAVOqdtFv/E JCEZYkKwpYGCGIiHS24OCUh12rGoX3L1FhhnjE/7HYX4BDt2VjQP1TrLE1wZt/wcH1pMBvbo1 UEPHSzvJtwo3I6s/vhD8e2WxtIk+wXnF1JJBxWSShObaoy0PfI232GRsr5m2oVCaW3krLh7F6 19vTrTNujRXDj8xuiAcn4qD1SHXA4cbek+adh/Y49kXhkEPnVTmP8gCfKQKw9mPT8B50kF52j 0MLP6slaKr82dwfgmVcjQliWzS/CmI6hapy7SvZ7QLztHo1ukJhv+nhnUTAcno82jFf6tIppS ArK8zIU7BxyJNFXLzeNUrZWH8eEFu8db0YjA/g== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In an effort to remove all instances of 'struct timeval' from the kernel, I'm changing the powerpc mpic_timer interface to use plain seconds instead. There is only one user of this interface, and that doesn't use the microseconds portion, so the code gets noticeably simpler in the process. Signed-off-by: Arnd Bergmann --- Submitted in November 2017, no reply, resending. Please apply. --- arch/powerpc/include/asm/mpic_timer.h | 8 ++--- arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c | 16 ++++----- arch/powerpc/sysdev/mpic_timer.c | 55 ++++++----------------------- 3 files changed, 21 insertions(+), 58 deletions(-) -- 2.9.0 diff --git a/arch/powerpc/include/asm/mpic_timer.h b/arch/powerpc/include/asm/mpic_timer.h index 0e23cd4ac8aa..13e6702ec458 100644 --- a/arch/powerpc/include/asm/mpic_timer.h +++ b/arch/powerpc/include/asm/mpic_timer.h @@ -29,17 +29,17 @@ struct mpic_timer { #ifdef CONFIG_MPIC_TIMER struct mpic_timer *mpic_request_timer(irq_handler_t fn, void *dev, - const struct timeval *time); + time64_t time); void mpic_start_timer(struct mpic_timer *handle); void mpic_stop_timer(struct mpic_timer *handle); -void mpic_get_remain_time(struct mpic_timer *handle, struct timeval *time); +void mpic_get_remain_time(struct mpic_timer *handle, time64_t *time); void mpic_free_timer(struct mpic_timer *handle); #else struct mpic_timer *mpic_request_timer(irq_handler_t fn, void *dev, - const struct timeval *time) { return NULL; } + time64_t time) { return NULL; } void mpic_start_timer(struct mpic_timer *handle) { } void mpic_stop_timer(struct mpic_timer *handle) { } -void mpic_get_remain_time(struct mpic_timer *handle, struct timeval *time) { } +void mpic_get_remain_time(struct mpic_timer *handle, time64_t *time) { } void mpic_free_timer(struct mpic_timer *handle) { } #endif diff --git a/arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c b/arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c index 1707bf04dec6..94278e8af192 100644 --- a/arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c +++ b/arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c @@ -56,17 +56,16 @@ static ssize_t fsl_timer_wakeup_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct timeval interval; - int val = 0; + time64_t interval = 0; mutex_lock(&sysfs_lock); if (fsl_wakeup->timer) { mpic_get_remain_time(fsl_wakeup->timer, &interval); - val = interval.tv_sec + 1; + interval++; } mutex_unlock(&sysfs_lock); - return sprintf(buf, "%d\n", val); + return sprintf(buf, "%lld\n", interval); } static ssize_t fsl_timer_wakeup_store(struct device *dev, @@ -74,11 +73,10 @@ static ssize_t fsl_timer_wakeup_store(struct device *dev, const char *buf, size_t count) { - struct timeval interval; + time64_t interval; int ret; - interval.tv_usec = 0; - if (kstrtol(buf, 0, &interval.tv_sec)) + if (kstrtoll(buf, 0, &interval)) return -EINVAL; mutex_lock(&sysfs_lock); @@ -89,13 +87,13 @@ static ssize_t fsl_timer_wakeup_store(struct device *dev, fsl_wakeup->timer = NULL; } - if (!interval.tv_sec) { + if (!interval) { mutex_unlock(&sysfs_lock); return count; } fsl_wakeup->timer = mpic_request_timer(fsl_mpic_timer_irq, - fsl_wakeup, &interval); + fsl_wakeup, interval); if (!fsl_wakeup->timer) { mutex_unlock(&sysfs_lock); return -EINVAL; diff --git a/arch/powerpc/sysdev/mpic_timer.c b/arch/powerpc/sysdev/mpic_timer.c index a418579591be..87e7c42777a8 100644 --- a/arch/powerpc/sysdev/mpic_timer.c +++ b/arch/powerpc/sysdev/mpic_timer.c @@ -47,9 +47,6 @@ #define MAX_TICKS_CASCADE (~0U) #define TIMER_OFFSET(num) (1 << (TIMERS_PER_GROUP - 1 - num)) -/* tv_usec should be less than ONE_SECOND, otherwise use tv_sec */ -#define ONE_SECOND 1000000 - struct timer_regs { u32 gtccr; u32 res0[3]; @@ -90,51 +87,23 @@ static struct cascade_priv cascade_timer[] = { static LIST_HEAD(timer_group_list); static void convert_ticks_to_time(struct timer_group_priv *priv, - const u64 ticks, struct timeval *time) + const u64 ticks, time64_t *time) { - u64 tmp_sec; - - time->tv_sec = (__kernel_time_t)div_u64(ticks, priv->timerfreq); - tmp_sec = (u64)time->tv_sec * (u64)priv->timerfreq; - - time->tv_usec = 0; - - if (tmp_sec <= ticks) - time->tv_usec = (__kernel_suseconds_t) - div_u64((ticks - tmp_sec) * 1000000, priv->timerfreq); - - return; + *time = (u64)div_u64(ticks, priv->timerfreq); } /* the time set by the user is converted to "ticks" */ static int convert_time_to_ticks(struct timer_group_priv *priv, - const struct timeval *time, u64 *ticks) + time64_t time, u64 *ticks) { u64 max_value; /* prevent u64 overflow */ - u64 tmp = 0; - - u64 tmp_sec; - u64 tmp_ms; - u64 tmp_us; max_value = div_u64(ULLONG_MAX, priv->timerfreq); - if (time->tv_sec > max_value || - (time->tv_sec == max_value && time->tv_usec > 0)) + if (time > max_value) return -EINVAL; - tmp_sec = (u64)time->tv_sec * (u64)priv->timerfreq; - tmp += tmp_sec; - - tmp_ms = time->tv_usec / 1000; - tmp_ms = div_u64((u64)tmp_ms * (u64)priv->timerfreq, 1000); - tmp += tmp_ms; - - tmp_us = time->tv_usec % 1000; - tmp_us = div_u64((u64)tmp_us * (u64)priv->timerfreq, 1000000); - tmp += tmp_us; - - *ticks = tmp; + *ticks = (u64)time * (u64)priv->timerfreq; return 0; } @@ -223,7 +192,7 @@ static struct mpic_timer *get_cascade_timer(struct timer_group_priv *priv, return allocated_timer; } -static struct mpic_timer *get_timer(const struct timeval *time) +static struct mpic_timer *get_timer(time64_t time) { struct timer_group_priv *priv; struct mpic_timer *timer; @@ -277,7 +246,7 @@ static struct mpic_timer *get_timer(const struct timeval *time) * @handle: the timer to be started. * * It will do ->fn(->dev) callback from the hardware interrupt at - * the ->timeval point in the future. + * the 'time64_t' point in the future. */ void mpic_start_timer(struct mpic_timer *handle) { @@ -319,7 +288,7 @@ EXPORT_SYMBOL(mpic_stop_timer); * * Query timer remaining time. */ -void mpic_get_remain_time(struct mpic_timer *handle, struct timeval *time) +void mpic_get_remain_time(struct mpic_timer *handle, time64_t *time) { struct timer_group_priv *priv = container_of(handle, struct timer_group_priv, timer[handle->num]); @@ -391,7 +360,7 @@ EXPORT_SYMBOL(mpic_free_timer); * else "handle" on success. */ struct mpic_timer *mpic_request_timer(irq_handler_t fn, void *dev, - const struct timeval *time) + time64_t time) { struct mpic_timer *allocated_timer; int ret; @@ -399,11 +368,7 @@ struct mpic_timer *mpic_request_timer(irq_handler_t fn, void *dev, if (list_empty(&timer_group_list)) return NULL; - if (!(time->tv_sec + time->tv_usec) || - time->tv_sec < 0 || time->tv_usec < 0) - return NULL; - - if (time->tv_usec > ONE_SECOND) + if (time < 0) return NULL; allocated_timer = get_timer(time);