From patchwork Mon Nov 27 11:31:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 119676 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp119739qgn; Mon, 27 Nov 2017 03:33:38 -0800 (PST) X-Google-Smtp-Source: AGs4zMa86JQXICfU2lLm7nV5KEvXyb2f0pkRcyUP5+aOJ8wxI6EHRgjbgBuHP/yRXpTlizjPI4SY X-Received: by 10.84.241.204 with SMTP id t12mr37990860plm.93.1511782418446; Mon, 27 Nov 2017 03:33:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511782418; cv=none; d=google.com; s=arc-20160816; b=kde3PibEUckIkTtbk6vkYGKS4H8ICubrJ4JSG/24dDRiiG4LY/qySjTlhjaQVfIrGV mdbIkOhZjUkjpDxqKFnmouMac2enAZprBg+Z7xWNYhvxJsKkwLx3Q65kQm0519NL+6Ui tl5L8fX4FT7YmabTGR8Z0XLB1gGYSr520EXjOKkxfHfFP3JvbE1CEzcZ6GauBH35SPk/ fr02F69y6OUCvTg+qtrDFjkKmu3XVAugSYk0v8DRwpYYVbN89b8a8bX3vcW065Ev/PmJ xAfXSsAY31oapcoBRdUyKMGYGEkCt2bIz2ETAGXabqo1cpF5PSqMoovylKU+xOvVGnSi cwHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=kdQJrisDMg53JrA7QZEyRpcNcC7XgHcRns/txzuK9u8=; b=btrNbjAqAARqU7HLvfDpv2z5ukbFDNqbYaYtwNH1xwANQNaKaawOOEwf2nrLDmKYgu DYTQ0HniJGi4glRx1RLC0StSJVwoBz4Vn5/0/8Z21w6DZrYZMCK0dVH118u+R9yydssL xXyw03l8vGHPjQXoVqZX927Y6au0G3lHAhAPylPmQ2VI06JKTcSNlqbI73BQYR9xykAq OLnm+s2vtflvhqXZlF8H4IilggGrlc369Aq3lA0h1t8tubMqp1bBzvOhSwZ1vxBfXjic djDfgTVehGrvcGEoxVzeuwyP8ko+ukSO40Y0u9phTFzoN2LVvpB3Rf76LDqL5fMpdX4U UFQA== 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 h2si4617956pli.718.2017.11.27.03.33.38; Mon, 27 Nov 2017 03:33:38 -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 S1752115AbdK0Ldh (ORCPT + 28 others); Mon, 27 Nov 2017 06:33:37 -0500 Received: from mout.kundenserver.de ([212.227.126.187]:62397 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751451AbdK0Ldf (ORCPT ); Mon, 27 Nov 2017 06:33:35 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue001 [212.227.15.129]) with ESMTPA (Nemesis) id 0MYXfl-1eetAC0IoD-00V9sN; Mon, 27 Nov 2017 12:33:25 +0100 From: Arnd Bergmann To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: y2038@lists.linaro.org, Arnd Bergmann , Tyrel Datwyler , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] powerpc: mpic_timer: avoid struct timeval Date: Mon, 27 Nov 2017 12:31:56 +0100 Message-Id: <20171127113234.2186374-2-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20171127113234.2186374-1-arnd@arndb.de> References: <20171127113234.2186374-1-arnd@arndb.de> X-Provags-ID: V03:K0:wPeFIaUrr83VfDi+d4D/in35+h+CVPsj0rtVrnpkj8sSrrw486+ riEpYUVoV4GKFTUtrlBo6YBTcxLAdda+gn3/nI8jhFHeSwmlkCa9a7qYSgpnxnqbWt73Q6z BgwV/jkosj8LN1tL5vDZjeHiY0GtJXQ9YdfAuoYsARDLD8YZvJ/jeERsrXp8iV9UlXQOyr/ XXpWoO5+YUSNxtSe6+RBw== X-UI-Out-Filterresults: notjunk:1; V01:K0:mzei/uOQ52A=:L+KPbbXv042JXLyvFCfjim kHGWsCZm2IDVXpSYIAWwXshOcSDMwNenAdhAYydK7cPNKPzKTvXu4V14dpo+Yg4MlKSYkrYru 71Is92rya6tij5pEaUVjDPbBHrhc3wmU6GCEna5QjFKkG8eo6EMRGgtHSfKhxblJNSGHQqU3f pYjjjyeOZLjk73WZjFIRL1InXW0I0WYmkIa3chRp5y5zIqMy0cDyt1Bz5sBFYNekNPnI5QrMz +74h5/k8DOKw61Ky2nT5d4cK3DmzbSe4v5h8MQc1VZ9i/ivLw4JOnNo5ATTDSMZHQr3si73E1 dMgvWAiwFy6mq/5HIjZ172GE+EdmDC/nt6AHjS0f+1wKQjZosAqZe6uDBh0gJdLXcGMUL23NJ l8eqN0IEPCv/4yCEPyHXfAq/xnqysNy6LzyvK3jxGa5BHRq4blGTp4VqQrj4fwxHXF65cnvZg gQ1Wms4Ol80JMiVDfR6tVW+oz8u/LxS5YjefpteZZNruR9cxQdbpcRJQDEuT3nLikFDW4gCye fWG08E8E5uFchrGNs2rljxytGEMWOClNv39pGqqR1ea3It/D4Jhyx+hWLw4KXscpbdRbnt7q0 ysLqqUnK1WfKiKltmc9znENP4Krj2EIAkwmFIeHChAQ7lQxI1HdtSNp16j4ZonQg0I5F9EO6S L6xW5etFQlMRlRRgnijy5Rc0yjjgBfvLEuu1izI4JdgiP5mMVeg5Lc6xIG2kBReEDp+nb6Ixq zVuaWahZHXn30alsJB6o06XIycQ9im0J8l1KVwuz+Jn+iCVnKlCdwkVUTjc= 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 --- 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);