From patchwork Mon Nov 27 11:31:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 841646 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yllFr4qcBz9rvt for ; Mon, 27 Nov 2017 22:39:44 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yllFr3jKkzDrK5 for ; Mon, 27 Nov 2017 22:39:44 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=arndb.de (client-ip=212.227.126.134; helo=mout.kundenserver.de; envelope-from=arnd@arndb.de; receiver=) X-Greylist: delayed 332 seconds by postgrey-1.36 at bilbo; Mon, 27 Nov 2017 22:38:34 AEDT Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3yllDV13SbzDqyG for ; Mon, 27 Nov 2017 22:38:33 +1100 (AEDT) Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue001 [212.227.15.129]) with ESMTPA (Nemesis) id 0MLnvv-1eISIz3WVP-000rQ5; Mon, 27 Nov 2017 12:32:43 +0100 From: Arnd Bergmann To: Jeremy Kerr , Arnd Bergmann , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Subject: [PATCH 1/2] spufs: use timespec64 for timestamps Date: Mon, 27 Nov 2017 12:31:55 +0100 Message-Id: <20171127113234.2186374-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:EW6biBrOwFS17p+nniKdYxm3pWRwXsIBMX3kxHXxtjIAEDmPw+K +XqSaT2/Jpctb6S2oj0W4NbjNSn9rPO2DBzJjcbpwq5snH6d7bbu44+sxI+tshiO6OzKeRQ BTxxDsQZ2cV0K+wFbQo2Ooq5s1UHIAW6tbRHuncIX3BOjgF9cfHpdUoT4PZk4iC5ATZ1HB2 IYqihV5hNGCtvOjAXWENg== X-UI-Out-Filterresults: notjunk:1; V01:K0:velnAKGAmbM=:olXDEGkuX/NuvRSrJG6BIa hkGBcXKOuPWpdIULC8OjWX2Or2kWwcvsXgtayrYU1lFRf1wfuZSRj7J9oDp3WJ9sjkctCpvaJ /XatQBz53Mxw5z4eB69teZBvnm6bIO07S0pXjxZrsY5ggUin01iQDxnMganL8wI1k2QxPYeeP JqImmx6NO9by4hnWIW4ExEvTpI/KTwqAuSrmQ2BWFISuDGtX2RuKURSWsCRo6bldabCrJajR5 MvEYfaDaXoFvTM7yBjxPWaLwQADnJ+/EvTy2nKJSMs3EViQ+SZnEQDdQHMhNZimdX/BMYdDuJ kPHqOtEqfDjY+b9cA7KrVahbHY5M0Kc62sx/+55b2l1obuAFKbL3oNwYPx+tUTQ8SpLs5g7ns NgmAj5aMg/o/BvFYs7NmnU/zkwYusSjxWKx/ZZ6JBIs8cijVNk07KwynjnQEcBTFwDls1jNde X5pnsrNzAoFyEHKIkDqyzN1hQ1L0JbKnoFI5yyTMcxnQNXDyBm39+gOW/efUeQm4wmQcqeBFC pDwsWulWwNkQAjWC1HF2nlfjHzOraL7N9uhv+wo057CVzstoq87NhWjIYjkc9ZgOS1i1Dj16g tJiM8RtDx5NRWshDLUXsRluBjZCYZjDcaYu9NwpOq1TI1d0zmfwWWMiojVYqhuqBSIPQVdR2h olvz8+XHxzGQdevdR3eKZ2OxAKDKlXi8DH9w5oYO1EkPLLBzHBbrq3HZYYZ9LvrfnCTzp98bR EFZKKglvdtwEs7Y9Msy9QCK9GYVdmi2D8VHfKA== X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: y2038@lists.linaro.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The switch log prints the tv_sec portion of timespec as a 32-bit number, while overflows in 2106. It also uses the timespec type, which is safe on 64-bit architectures, but deprecated because it causes overflows in 2038 elsewhere. This changes it to timespec64 and printing a 64-bit number for consistency. Signed-off-by: Arnd Bergmann --- arch/powerpc/platforms/cell/spufs/file.c | 6 +++--- arch/powerpc/platforms/cell/spufs/spufs.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c index 5ffcdeb1eb17..94139135be9c 100644 --- a/arch/powerpc/platforms/cell/spufs/file.c +++ b/arch/powerpc/platforms/cell/spufs/file.c @@ -2375,8 +2375,8 @@ static int switch_log_sprint(struct spu_context *ctx, char *tbuf, int n) p = ctx->switch_log->log + ctx->switch_log->tail % SWITCH_LOG_BUFSIZE; - return snprintf(tbuf, n, "%u.%09u %d %u %u %llu\n", - (unsigned int) p->tstamp.tv_sec, + return snprintf(tbuf, n, "%llu.%09u %d %u %u %llu\n", + (unsigned long long) p->tstamp.tv_sec, (unsigned int) p->tstamp.tv_nsec, p->spu_id, (unsigned int) p->type, @@ -2499,7 +2499,7 @@ void spu_switch_log_notify(struct spu *spu, struct spu_context *ctx, struct switch_log_entry *p; p = ctx->switch_log->log + ctx->switch_log->head; - ktime_get_ts(&p->tstamp); + ktime_get_ts64(&p->tstamp); p->timebase = get_tb(); p->spu_id = spu ? spu->number : -1; p->type = type; diff --git a/arch/powerpc/platforms/cell/spufs/spufs.h b/arch/powerpc/platforms/cell/spufs/spufs.h index 5e59f80e95db..5d85c689c2e9 100644 --- a/arch/powerpc/platforms/cell/spufs/spufs.h +++ b/arch/powerpc/platforms/cell/spufs/spufs.h @@ -69,7 +69,7 @@ struct switch_log { unsigned long head; unsigned long tail; struct switch_log_entry { - struct timespec tstamp; + struct timespec64 tstamp; s32 spu_id; u32 type; u32 val; 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: 841648 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yllHZ1b25z9t0F for ; Mon, 27 Nov 2017 22:41:14 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yllHZ00WgzDrKl for ; Mon, 27 Nov 2017 22:41:14 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=arndb.de (client-ip=212.227.126.133; helo=mout.kundenserver.de; envelope-from=arnd@arndb.de; receiver=) Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3yllFK59GvzDrMB for ; Mon, 27 Nov 2017 22:39:17 +1100 (AEDT) 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 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:ICaP/zU12Fg=:Gyx98pzpJ2wCrlSE+yMirB /Q6Qdv2AX7CO4KfcqtMgqVuyuuBhNGj0gFqC+H9xZWhaEiiFUIi8Iq9uYy3bSGTsW/au0OePT gqVHAMbzLR1lS7+MER5gc0YX2MppU9QIeY+mXL8r/G2cJIm6FbVWjWtb8eGbu97SX22e3l/vk Tfu0tymewpWI5BW1eC4sdc3ruBqZuksTazwSTX+wGr/Bwm99FNRptPRnjNAVPNrLEtQ/yz9ZB 8BdTosDwqaoRPPq1ENSYpKCyuZz9OuxFcSibRucd19GUrANq9VUNjSyzBX/JfMcJrjK4LwQQF 4U6MPx7UmU3ZqW3atAPzceMEj/NvO5nAfbCd5QifeevRzHQEjr6l8iptj8fDdQxltZkDf9H4t poQbOtwosTxLNu1CnITtvdOy6PjkpS3COPbWPK7kAhs8LIhtOUb93Qw9pYoZ+O0hvljo3sBVs LFRuuuIhG63E+cSZy+FhhTHhAOdBczDh5YSAhmbB2p5WeXjLobp+U0fgJhlOaDeW6J056OY9M WRyyuIAsvOeGsKbmgbhbX+f/mMpXv0UzrcanBYGl2DHlum+l/7ToiBEO9H5SO31Mlu5PeL2Y/ o4q/s7UVh9OF1YWLkwctZVA7s3u2SGRSTGcG00b4h6ePxnjBnux/aV3DUXDTcG+eceaI97YPl 5MA0ycNObRukW6afNzw373S25o0rMleWbGzgqbmmmYASskaj4g+SKE6GZt8bke9z/V9bYULHV pzFhOyaGOqnMtVvg0tS1UXyH/v013BF8829QMtxQ8TByRM20kBN21Dpa9pI= X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: y2038@lists.linaro.org, linuxppc-dev@lists.ozlabs.org, Tyrel Datwyler , Arnd Bergmann , linux-kernel@vger.kernel.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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(-) 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);