Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2111146pxf; Sat, 20 Mar 2021 04:59:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwogdY95D2EZ5A483ot4VLVhsSsQD2BuYe9reXfHLwsxSWeBLhX2pXfAipbZDVkTp8eCIP9 X-Received: by 2002:a05:6402:2552:: with SMTP id l18mr14821393edb.71.1616241547523; Sat, 20 Mar 2021 04:59:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616241547; cv=none; d=google.com; s=arc-20160816; b=eIPo2IrS3xhnq6DBcRnMde/8jMXHHs3xZP1npyyT/1hr56rChrF4tDtOh21jht07y/ KSJYpA2Ry6xAGgbFfBs/2T3rvDePhBSA4m1VLRnmhu1tg8Fd8THIn3/n5o1JZkd9Of2C LHUi7cbuDMla8946knY911y0MHmQZ7rq05cWLCnnRODEDMAXHXCTK8AK+tf5FVUZjs0m 12Jf/GmvQ5yKZkEIirsuPSvSZsMik98nvclqPLGqDC/OfSOe7VHHhcwbP1ptOcZej8Kp F3BG1EHqyc3tNp4NeDjfVqzkiO4msJct8oVtMjIcaii6t5DLul5fCOny30jIdIWMuKfH rq9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=iW6uEND/ee4z9nsY45Ct1nMMtCxhIAfu1tQ3+1cotts=; b=ex0Lgl/vgeDcDsgdYfRbTT+u4bT4tKkQEyLRIIPHYzv5AaYLXtDabic5pQzH0mySt1 oUNu8hYXwun2V09Rfs6/iy6r6raxDPwCPbR36Wjud2M8MeeFvrnRd348Py6yflXCU/3O S4rXCbZSLc0qOilcJ4MGqxgXPGu4M58aCd4ncONKnwOxI2cD6rpsNqQP3zOC5GzAK9eV BXX5NuS9/IAcmQ+tr31vGBs8eBvoYMPbSEvfE+W0bvKzqpMb5L0Eld+g1paj9rM9qzeS Ifkrq5vlZrTdqzm5yfpAy8Q5jFiM1vv7y0/I8KCNNx6e80oG0bgo7ANwovwxeFxKLUvc N4dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wLwkmsu6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id t4si6559262ejs.517.2021.03.20.04.58.45; Sat, 20 Mar 2021 04:59:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wLwkmsu6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S229505AbhCTL5I (ORCPT + 99 others); Sat, 20 Mar 2021 07:57:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229510AbhCTL4t (ORCPT ); Sat, 20 Mar 2021 07:56:49 -0400 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E792C061762 for ; Sat, 20 Mar 2021 04:56:48 -0700 (PDT) Received: by mail-lj1-x234.google.com with SMTP id y1so15105028ljm.10 for ; Sat, 20 Mar 2021 04:56:48 -0700 (PDT) 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=iW6uEND/ee4z9nsY45Ct1nMMtCxhIAfu1tQ3+1cotts=; b=wLwkmsu6NNP9mQmkjv7ejqH3OpzE5jvfSZulXF8H1sT0nER01jIDIk0grBkN7izpfg MHgQQW7XPoLPZBFD8vBlF7SW1DvimWMx1aX66Md7W2VStJr4obJPegLzrZw6lX/nP6Kq cdCoYEUXKjzGSLe9DEtRGU+k2Iu8PlwWEJa7KbXCzi4hl1IhIk44mWa0CalP++vSFhY+ /tUpBFYE9GQfcGcGtVkj+zxeJxGNcNn6VyaQJL7ShZ6o+ch1zrbkAoAsmjU4UXLpW16L KL8YI0PwwwdOMV7OwMtMLsgr2F7RgXpuGAXFQ/xT4jXCpvn/zdJwyqyGe21LaZ5c7b7x x4sw== 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=iW6uEND/ee4z9nsY45Ct1nMMtCxhIAfu1tQ3+1cotts=; b=WquTjcuwf9CI7IjWaZgjHthA865gP5co77aAsaEbOM2K/bbahNEaotzIwoxsRTvfFh 6OM5cxGe52Bp6eSdCiKQJm3vvQ1uGwDh0twIMgrwzIxCesUNlyS9T22NH3fDezfW1uKK 09OSdPySpalpPIFH8lMrrQvqfbTwmXnnica4NLbUgEBq8bWU0AH6fz3FLOrBJ5x8P0/3 P8M2k6yt7W2TgT/LtD9+9malfVsdlQz/NokJBLLV7yNIXOT3tkBl6qJ9/bBFIT8MS8Jl IpzF5tXYc0th5r0WWJV723W9NoTNxPSg0YzaAOZgDUOqJAjdeQCyWAtZF3KVSnmKpt9j 2MdA== X-Gm-Message-State: AOAM533Wnzk7akuW8oCPZsl1R0zB3MGetGQ0IGKQHVbCEw0NJe63uIk8 R2w0H7pzm8SU4V7avN7/JgJ4+GkCbZDD41ya0nhE5g== X-Received: by 2002:a2e:864a:: with SMTP id i10mr3444104ljj.467.1616241407174; Sat, 20 Mar 2021 04:56:47 -0700 (PDT) MIME-Version: 1.0 References: <4c46726d-fa35-1a95-4295-bca37c8b6fe3@nvidia.com> In-Reply-To: <4c46726d-fa35-1a95-4295-bca37c8b6fe3@nvidia.com> From: Linus Walleij Date: Sat, 20 Mar 2021 12:56:36 +0100 Message-ID: Subject: Re: GTE - The hardware timestamping engine To: Dipen Patel , Kent Gibson Cc: "linux-kernel@vger.kernel.org" , "thierry.reding@gmail.com" , Jon Hunter , Bartosz Golaszewski , "open list:GPIO SUBSYSTEM" , linux-tegra , Thomas Gleixner , Arnd Bergmann Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Dipen, thanks for your mail! I involved some other kernel people to get some discussion. I think Kent Gibson can be of great help because he is using GPIOs with high precision. We actually discussed this a bit when adding support for realtime timestamps. On Wed, Mar 17, 2021 at 11:29 PM Dipen Patel wrote: > Nvidia Tegra SoCs have generic timestamping engine (GTE) hardware module which > can monitor SoC signals like IRQ lines and GPIO lines for state change, upon > detecting the change, it can timestamp and store in its internal hardware FIFO. > The advantage of the GTE module can be realized in applications like robotics > or autonomous vehicle where it can help record events with precise timestamp. That sounds very useful. Certainly the kernel shall be able to handle this. > ============ > For GPIO: > ============ > 1. GPIO has to be configured as input and IRQ must be enabled. > 2. Ask GPIO controller driver to set corresponding timestamp bit in the > specified GPIO config register. > 3. Translate GPIO specified by the client to its internal bitmap. > 3.a For example, If client specifies GPIO line 31, it could be bit 13 of GTE > register. > 4. Set internal bits to enable monitoring in GTE module > 5. Additionally GTE driver can open up lanes for the user space application > as a client and can send timestamping events directly to the application. I have some concerns: 1. GPIO should for all professional applications be used with the character device /dev/gpiochipN, under no circumstances shall the old sysfs ABI be used for this. In this case it is necessary because the character device provides events in a FIFO to userspace, which is what we need. The timestamp provided to userspace is an opaque 64bit unsigned value. I suppose we assume it is monotonic but you can actually augment the semantics for your specific stamp, as long as 64 bits is gonna work. 2. The timestamp for the chardev is currently obtained in drivers/gpio/gpiolib-cdev.c like this: static u64 line_event_timestamp(struct line *line) { if (test_bit(FLAG_EVENT_CLOCK_REALTIME, &line->desc->flags)) return ktime_get_real_ns(); return ktime_get_ns(); } What you want to do is to add a new flag for hardware timestamps and use that if available. FLAG_EVENT_CLOCK_HARDWARE? FLAG_EVENT_CLOCK_NATIVE? Then you need to figure out a mechanism so we can obtain the right timestamp from the hardware event right here, you can hook into the GPIO driver if need be, we can figure out the gpio_chip for a certain line for sure. So you first need to augment the userspace ABI and the character device code to add this. See commit 26d060e47e25f2c715a1b2c48fea391f67907a30 "gpiolib: cdev: allow edge event timestamps to be configured as REALTIME" by Kent Gibson to see what needs to be done. 3. Also patch tools/gpio/gpio-event-mon.c to support this flag and use that for prototyping and proof of concept. > ============ > For IRQ: > ============ Marc Zyngier and/or Thomas Gleixner know this stuff. It does make sense to add some infrastructure so that GPIO events and IRQs can use the same timestamping hardware. And certainly you will also want to use this timestamp for IIO devices? If it is just GPIOs and IRQs today, it will be gyroscopes and accelerometers tomorrow, am I right? Yours, Linus Walleij