From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752954AbbJWNvw (ORCPT ); Fri, 23 Oct 2015 09:51:52 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:61078 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752829AbbJWNvt (ORCPT ); Fri, 23 Oct 2015 09:51:49 -0400 From: Arnd Bergmann To: y2038@lists.linaro.org Cc: Pingbo Wen , dmitry.torokhov@gmail.com, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org Subject: Re: [Y2038] [PATCH V2] hil_mlc: convert timeval to ktime_t Date: Fri, 23 Oct 2015 15:51:44 +0200 Message-ID: <4159188.UVvamn6mDa@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) In-Reply-To: <05CEA4E0-A8CF-42DA-89C3-F0968DE73CB4@linaro.org> References: <46052377.96MapaKFAy@wuerfel> <33014393.CcP7q7PhGq@wuerfel> <05CEA4E0-A8CF-42DA-89C3-F0968DE73CB4@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:RVk51j/ZFsAHVY4Dr1t5CUneBI5WaD8SmoxWcrCtSaLDZ33Cq8N 1YoFa90aQJo5ghOw1X00cu3jixYbC0UuuREAV7i+6pDtuCObXx1sVK5P2TrkEzaXNy2umHO 0hyloD4+ckT9bk8imwW6/UkVCj9jaStC0pvPbRAhEoDHFoiDz7kaZlEr+mlnOPe5Hk5vsDJ 96SKFdxbwGHN9Upq+MF7A== X-UI-Out-Filterresults: notjunk:1;V01:K0:LN9rUHpYK8Y=:MgOjKgieO/xfqkTz2Dv1QD g1a1f2VJWWhcKJOG99nzEfY9dNOqRAO/lKDWG+Xzie4CTJh2qyeUtYpWsKhO3A19R5EiZ4Z2M NHqmYsh0J5sYvsHYrE/0OJYFbxxfuny+46kM1ABEGL8ma97ra253+lCIc/mBneYA2543Zj5zs X9LzVjJOGVVTJzn6ZKikt0gYltuO0C1E0sHJuWwHcJVeEi+UfLWhYGzlrmUJUl2fpK9OIRQ74 0c0yw6QmwKHfqRf+6z6S/x4EoRT7h53AGX0bJcinvzza4A8NsAdeC80LDMrvOYml9yUfciA2o u4Ei/q0lgiGF+Be0yqU+8SCwJKlzhIpy0QU5IDzQT+8twhcaMD9CPi+PxZFX4g1DZWA6Sy1Ec ++aQqKoWax5vrbmORr7cxnJAkmJKSXgP28Z4iYfk3vkhU62UAOSmI8rMTCU67+5MlzQJ6C6u/ eBrab75a153URWRNv0CrSwKAc4wWoRsXR6Aw7r0BPdzE37UXALSR2gmTGK3OzZHLKsRv61x6l k4Imda1j/T0pq9TXBPkiFqVHzmw8Ua71rFPxx4GuYAoN54Ql2OgfB0eaxts7ldPwm1YlxXPj/ x/IDZ3bx8DwThktu9p035YKfF5+oeEL9M91dGH1+rpj9HEHtgVfSCBw5xJlh5eMFMKYssPeMF ABJ1ZM63aKcQA3dSCLbwDONLiXjDOOci4/1dfZXb5nLx4OxOMrs+deIC7DMwIVwzmvgQ3Gs3L 4ooFPLpwLTvF52fy Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Friday 23 October 2015 20:32:50 Pingbo Wen wrote: > >> - do_gettimeofday(&tv); > >> - tv.tv_usec += USEC_PER_SEC * (tv.tv_sec - mlc->instart.tv_sec); > >> - tv.tv_usec -= mlc->instart.tv_usec; > >> - if (tv.tv_usec >= mlc->intimeout) goto sched; > >> - tv.tv_usec = (mlc->intimeout - tv.tv_usec) * HZ / USEC_PER_SEC; > >> - if (!tv.tv_usec) goto sched; > >> - mod_timer(&hil_mlcs_kicker, jiffies + tv.tv_usec); > >> + if (tmp.tv64 >= (mlc->intimeout * NSEC_PER_USEC)) > >> + goto sched; > >> + tmp.tv64 = mlc->intimeout * NSEC_PER_USEC - tmp.tv64; > >> + if (tmp.tv64 < NSEC_PER_USEC) > >> + goto sched; > >> + mod_timer(&hil_mlcs_kicker, > >> + jiffies + nsecs_to_jiffies(tmp.tv64)); > >> break; > >> sched: > >> tasklet_schedule(&hil_mlcs_tasklet); > > > > If I read this right, the code is executed one for each input event such > > as a keypress or mouse movement. In the latter case, doing nsecs_to_jiffies() > > here is actually a bit expensive, and I stil think it can be avoided > > by just using jiffies. > > > > For the (tmp.tv64 < NSEC_PER_USEC) part, did you just do that because > > I said this, or did you actually prove that it is required? I'm still > > confused about what the driver is trying to achieve here. > > More explanation here:) > the judgement here is to prevent mod_timer with zero delta. I can not > make sure whether the module have nanosecond precise, so just keep same. Ok, I guess I was misreading the original code. What it actually does is to check the remaining time in jiffies, not in microseconds, so the algorithm is: if (already expired) schedule tasklet else { convert to jiffies if (expired just now) schedule tasklet else schedule tasklet from timer } So the entire code is meant to guarantee that the tasklet is getting scheduled, and the first two cases are just an optimization to avoid going through the timer. I checked the code for mod_timer to verify that mod_timer with an argument in the past will just cause the handler to be called at the next tick, so we don't really need the middle case, and the logic becomes really simple if you use jiffies instead of ktime_t. Arnd