Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3385719ybf; Tue, 3 Mar 2020 05:08:36 -0800 (PST) X-Google-Smtp-Source: ADFU+vsSW4Puz2AF/iMSyydLeXD/0jeCjxGk4XlRkUCOW2ZcjCAxzmnPTNqYfpN/FPEa67lTm8Vg X-Received: by 2002:a05:6830:155a:: with SMTP id l26mr3318106otp.339.1583240916647; Tue, 03 Mar 2020 05:08:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583240916; cv=none; d=google.com; s=arc-20160816; b=gzc2YxH37CjmF3X5L8HWYKKlZUtR6bdEUOgbSiDEi7HuvJMMFTBd/26nneBHTvrFi3 5YpqDwzmdPL4ZAkJiecV7ribFeFF2ZAaBvUVkzExX+96fPXyqL9hj+Y5v//QkdCm70XY FZBCK4LpftgPgbfjfGrph1yEX3hPGepmjXz2WVmT7w+P/9yx3P4pQEwaC2ykwBuo+poX R5I7iQsH3x1Vpe5BD3V7LSib1c4scqU5UHuqBeAyu8lvZVPsU0+KlLQKcGymYBh8DVvp lPXh2kzwQUU18R+qdFVq52jYa1YvUn4+2Vg8sAhdcNiPEYfeurOQfC8rcoCja+Kssjt8 tasQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=NKj+1Rf5TnGZp4SiLcelNGaJtNpD2JrLWM1tk/In9ck=; b=LqzeGv4r5UAx3jFGHwGxgm8zxoy7AFqFWIwnlbAuWd6Pitqe8h5MNAzg4kgjS92cbO mJxYZaI1QanY6eqvydhQy9ID83OO9S5fBiSd5epShVqsIeX0ww6qjkJxXOKMAimeI5rG qkbOUHSzwAKWB429BormMtT84Sv1DyVdubsoKPCtQsePyHZQTeuS2M4P94Sp82tE/5xM de0twOyVg+cz5K1hEufv6L0deY0XZAvS+osYlmLM7OyEqsw7+a5j4v74QQaHIweotV8p mQBfSzqWdeYNdU2GzPzArvAv/1nCKx+N8TjJvQBTjh2uLUtiLUMfdRM8Nu08nFy/Hzw0 CR9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jx1mKKrA; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v15si4592267oif.59.2020.03.03.05.08.21; Tue, 03 Mar 2020 05:08:36 -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; dkim=pass header.i=@linaro.org header.s=google header.b=jx1mKKrA; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728862AbgCCNBC (ORCPT + 99 others); Tue, 3 Mar 2020 08:01:02 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:44590 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728361AbgCCNBC (ORCPT ); Tue, 3 Mar 2020 08:01:02 -0500 Received: by mail-lj1-f196.google.com with SMTP id a10so3361116ljp.11 for ; Tue, 03 Mar 2020 05:01:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NKj+1Rf5TnGZp4SiLcelNGaJtNpD2JrLWM1tk/In9ck=; b=jx1mKKrApcRXamn0UdmROfGB/dWjaSxTUv6iyGimgChB2LNGywfc217cKIVp8ywKB0 5AFhGnzfgGLxwjwKwQ5z2C+zKUW7FUnqWZ7M9GUvS2VLhIBz95aJVpVDlX4gr5rt6Jl2 uhCZdMUDn5WD6z+3sbZ39l67QTde69vqXP09FAuXwfCWfPzVtplTJjgCUH5BLVXmE3Qe es3YU6cEE1TTCOgADetZuNWd7uC0DwwbRLe1A6RZTX25hMYSpWDKZcDtPqPvDYSKJhNi mhomdgxZ541z06qXd4tS9oeGlCUjzy2f9jyanXnJ+Qfuwm5McojSZczPgwijviXEPVgX 8uoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NKj+1Rf5TnGZp4SiLcelNGaJtNpD2JrLWM1tk/In9ck=; b=ogYBq7PD5+KKW2cDBusXUTCb2uCpz5wK2ZkDvfjEbNdgBd/Q5/RONMHpg1emeTgFoI aX+BMmSscMhZWoKaUVfR7c7v0BD0scXqBRS7Wq0Jlimp9oMA+KHJwG6msC0Z2crrud+d nSiLmCDZpI/p+trpSmjVOgsaXSNqFckTYz5vyvAlqLC4mRLT11dmb8hDzrvxZN2Xddn9 /z6NbwuPtjnbDsv5AcWcu6BjcdYWks7Nyla7YOu2WTPa1DHUySTDywBscAmIxfCbPfh+ dw7Q+s4mfVuYq+vgT0vKLZWWyfJcrzzUpDVCi0tD2HZ73no4b8Af7otZsLPcrmetv+dV k3Hw== X-Gm-Message-State: ANhLgQ3ste7OQDHTt5ucxQImQ8uSp9v2yWW0AG9OlkzL8b84Uw77EoVX sKOXnzc3Z+cvBQi0YrBFHMY3DlF+yDWbGmD+h2Ciww== X-Received: by 2002:a05:651c:2c7:: with SMTP id f7mr2343804ljo.125.1583240459705; Tue, 03 Mar 2020 05:00:59 -0800 (PST) MIME-Version: 1.0 References: <20191211214852.26317-1-christopher.s.hall@intel.com> <87eevf4hnq.fsf@nanos.tec.linutronix.de> <20200224224059.GC1508@skl-build> <87mu95ne3q.fsf@nanos.tec.linutronix.de> In-Reply-To: <87mu95ne3q.fsf@nanos.tec.linutronix.de> From: Linus Walleij Date: Tue, 3 Mar 2020 14:00:48 +0100 Message-ID: Subject: Re: [Intel PMC TGPIO Driver 0/5] Add support for Intel PMC Time GPIO Driver with PHC interface changes to support additional H/W Features To: Thomas Gleixner , Bartosz Golaszewski , Jonathan Cameron Cc: "Christopher S. Hall" , netdev , "linux-kernel@vger.kernel.org" , "H. Peter Anvin" , Ingo Molnar , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , jacob.e.keller@intel.com, Richard Cochran , "David S. Miller" , Sean V Kelley Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 27, 2020 at 12:06 AM Thomas Gleixner wrote: > "Christopher S. Hall" writes: > > Apart from clock import/export applications, timestamping single I/O > > events are potentially valuable for industrial control applications > > (e.g. motor position sensing vs. time). As time sync precision > > requirements for these applications are tightened, standard GPIO > > timing precision will not be good enough. If you are using (from userspace) the GPIO character device and open the events using e.g. tools/gpio/gpio-event-mon.c you get GPIO events to userspace. This uses a threaded interrupt with an top half (fastpath) that timestamps it as the IRQ comes in using ktime_get_ns(). It's as good as we can get it with just software and IRQs (I think). This uses a KFIFO to userspace, same approach as the IIO subsystem. > Anyway, the device we are talking about is a GPIO device with inputs and > outputs plus bells and whistles attached to it. > > On the input side this provides a timestamp taken by the hardware when > the input level changes, i.e. hardware based time stamping instead of > software based interrupt arrival timestamping. Looks like an obvious > extension to the GPIO subsystem. That looks like something I/we would want to support all the way to userspace so people can do their funny industrial stuff in some standard manner. IIO has a config file in sysfs that lets them select the source of the timestamp like so (drivers/iio/industrialio-core.c): s64 iio_get_time_ns(const struct iio_dev *indio_dev) { struct timespec64 tp; switch (iio_device_get_clock(indio_dev)) { case CLOCK_REALTIME: return ktime_get_real_ns(); case CLOCK_MONOTONIC: return ktime_get_ns(); case CLOCK_MONOTONIC_RAW: return ktime_get_raw_ns(); case CLOCK_REALTIME_COARSE: return ktime_to_ns(ktime_get_coarse_real()); case CLOCK_MONOTONIC_COARSE: ktime_get_coarse_ts64(&tp); return timespec64_to_ns(&tp); case CLOCK_BOOTTIME: return ktime_get_boottime_ns(); case CLOCK_TAI: return ktime_get_clocktai_ns(); default: BUG(); } } After discussion with Arnd we concluded the only timestamp that makes sense is ktime_get_ns(). So in GPIO we just use that, all the userspace I can think of certainly prefers monotonic time. (If tglx does not agree with that I stand corrected to whatever he says, I suppose.) Anyway in GPIO we could also make it configurable for users who know what they are doing. HW timestamps would be something more elaborate and nice CLOCK_HW_SPECIFIC or so. Some of the IIO sensors also have that, we just don't expose it as of now. Yours, Linus Walleij