Received: by 10.223.164.202 with SMTP id h10csp446907wrb; Thu, 30 Nov 2017 13:04:25 -0800 (PST) X-Google-Smtp-Source: AGs4zMbf8Lhpaka6F1RRfnpVsKFclqOmlOT60uTUdnvm2X3xrRhQMeoQjCmWWuofQBn7UBff+TCk X-Received: by 10.84.128.77 with SMTP id 71mr3879404pla.197.1512075865199; Thu, 30 Nov 2017 13:04:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512075865; cv=none; d=google.com; s=arc-20160816; b=bwU8Gsn911M3ZG2DDaC3nMLhnKbt4AhiFUcim2fjiu7StvSR44E2BRfjP7u8KIcrcI wNKG+HgTzaf32yAF7Gdk0wxGMuV7Q4fF4cOhFDpiZBoU4nDrMV4WO8JXvpUT6432RkTf 3gZF8OLx8DVXh5egAM/sSkzlLZKIE97fIeNAo/ffbuI4YwlHuKPaD1nE8kt5MB8pt+c6 CFNicfec8hhV4Q2JUcB4GMkqv6T2T9hU5dWuQIiBNhpmmnYl93t9aNYwi3DbOyaQYHwc WIDA6L9zgb4ec3RZBHEAXDuJ/W8zWxCXz+xBGtKIhguO2avWV7VCh8xA2yYx3ViGzdMr v5sA== 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 :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=5KiqBf6TklolxapMAkHZs7+fj3GqcNgbeYYuAD1RFvc=; b=vsU1op/2pEGuKkCvJ5driBHotRaGzQsa2CSiUgNDaYGYKnz0ULCjSK87e2qcStNCUG PX8J50xjmh7t6kguU3MkTbTN6Ti/TqqJpVdA0SD6VjrnzlDXbFTE8kCJ/cINwqdcmBYJ anJ3AKYSIB5cF5nb2g5yFkwncs3fWgAd/L6PG7FpwjyX79Oks0SC9+74FzpItYWLlF8F v60osPpouL4ljfNsHpxkxWc8RdBoK2xDOf+desRkn8p2DfFwn//s2Vg6CpM7rFXDnV1r vl3IxBHcQ111DwSMEVd/2qJdmjoaosU/uLJSoUWa/QksgftKUHjrPpOcN39sNxl0rw/J 13zA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dev-mellanox-co-il.20150623.gappssmtp.com header.s=20150623 header.b=s2sb4z0/; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.co.il Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u195si3521712pgb.261.2017.11.30.13.04.08; Thu, 30 Nov 2017 13:04:25 -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=@dev-mellanox-co-il.20150623.gappssmtp.com header.s=20150623 header.b=s2sb4z0/; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.co.il Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751197AbdK3VD6 (ORCPT + 99 others); Thu, 30 Nov 2017 16:03:58 -0500 Received: from mail-lf0-f52.google.com ([209.85.215.52]:40953 "EHLO mail-lf0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750801AbdK3VD4 (ORCPT ); Thu, 30 Nov 2017 16:03:56 -0500 Received: by mail-lf0-f52.google.com with SMTP id t197so9427646lfe.7 for ; Thu, 30 Nov 2017 13:03:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dev-mellanox-co-il.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=5KiqBf6TklolxapMAkHZs7+fj3GqcNgbeYYuAD1RFvc=; b=s2sb4z0/4a59x0kEX7ZJ39BCOlzYOJophSlKuQ2WhsjY1suNuJQhvI7b28FqohhfWJ srq03LgPjpfrc832k0IEvNfQV7ckU5b4c6DsoRgEEBq70M5COV2JK4D1ylcloPWt7BeI dyP9rj7ag+3/cvkJ/4rjC2ZuFZY5H6fkOBxavh0DK6mOYbPAKdCWtrbd9sZ8S4Km6E2x +mrEeUIC7WZbfJ65OMSm1Fzmg68ZzWVyD6Gzf+wu7L5m3uFQUU9eo7TU5rv3SDheYWt1 od4XBfV+OKNfS1uYE1p47aXUy2YWtvoDZkgGxa+vxUgpFHXD95+TDPxaLVjpLUfMGDfO K48Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=5KiqBf6TklolxapMAkHZs7+fj3GqcNgbeYYuAD1RFvc=; b=YgW2UIgG6ZuoXJsm+dPih4rrffVLFOlNgnTiZoh70/ra1zW/q3E8U+cc23kHGXShuj BT3JAPvlsVYraIk1nboDldijWubg+tcAfO4mccev+OjUCsabrTVUSuqPIsRzZ+FU/Isq w7se0DHeaBuTTUWsGyvVoVQa2i1Qft/jciFuaWBEw0UJQNDt7FFMNq4b3h+4yx+Wz9QE QooR2wlfLYw373fbMLRBU/HOqsCwSwIeZhzYHB/Bc7GuqipOwPwQc5zlhEY1Vnv1ZETv T0msvYHntRqngqr2RpZpHx9UPsT0CB15FM+S2JaZlFkvqoeFYx8H2bxHT1xIfjCQpIL+ pfQQ== X-Gm-Message-State: AJaThX5PAjDSRryVUzHyxCkXK+ZZ5m6TxoaqcMLjWGFgfcBDbtwarX71 +9mc6gTdK4YJBZPiND1rMqdPxwU6szkH7CHIvzkttA== X-Received: by 10.46.65.66 with SMTP id o63mr3813263lja.172.1512075834729; Thu, 30 Nov 2017 13:03:54 -0800 (PST) MIME-Version: 1.0 Received: by 10.25.190.21 with HTTP; Thu, 30 Nov 2017 13:03:34 -0800 (PST) In-Reply-To: <63a2a495-1bdb-5d47-1202-9b538e9601d8@intel.com> References: <1510748034-14034-1-git-send-email-sagar.a.kamble@intel.com> <1510748034-14034-2-git-send-email-sagar.a.kamble@intel.com> <151074872901.26264.3145709294590477412@mail.alporthouse.com> <83805c37-99b2-2922-e8e8-ea435f9da7d0@intel.com> <63a2a495-1bdb-5d47-1202-9b538e9601d8@intel.com> From: Saeed Mahameed Date: Thu, 30 Nov 2017 13:03:34 -0800 Message-ID: Subject: Re: Creating cyclecounter and lock member in timecounter structure [ Was Re: [RFC 1/4] drm/i915/perf: Add support to correlate GPU timestamp with system time] To: Sagar Arun Kamble Cc: Thomas Gleixner , John Stultz , Stephen Boyd , Chris Wilson , linux-kernel , Linux Netdev List , linux-rdma@vger.kernel.org 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 Mon, Nov 27, 2017 at 2:05 AM, Sagar Arun Kamble wrote: > > > On 11/24/2017 7:01 PM, Thomas Gleixner wrote: >> >> On Fri, 24 Nov 2017, Sagar Arun Kamble wrote: >>> >>> On 11/24/2017 12:29 AM, Thomas Gleixner wrote: >>>> >>>> On Thu, 23 Nov 2017, Sagar Arun Kamble wrote: >>>>> >>>>> We needed inputs on possible optimization that can be done to >>>>> timecounter/cyclecounter structures/usage. >>>>> This mail is in response to review of patch >>>>> https://patchwork.freedesktop.org/patch/188448/. >>>>> >>>>> As Chris's observation below, about dozen of timecounter users in the >>>>> kernel >>>>> have below structures >>>>> defined individually: >>>>> >>>>> spinlock_t lock; >>>>> struct cyclecounter cc; >>>>> struct timecounter tc; >>>>> >>>>> Can we move lock and cc to tc? That way it will be convenient. >>>>> Also it will allow unifying the locking/overflow watchdog handling >>>>> across >>>>> all >>>>> drivers. >>>> >>>> Looks like none of the timecounter usage sites has a real need to >>>> separate >>>> timecounter and cyclecounter. >>> >>> Yes. Will share patch for this change. >>> >>>> The lock is a different question. The locking of the various drivers >>>> differs and I have no idea how you want to handle that. Just sticking >>>> the >>>> lock into the datastructure and then not making use of it in the >>>> timercounter code and leave it to the callsites does not make sense. >>> >>> Most of the locks are held around timecounter_read. In some instances it >>> is held when cyclecounter is updated standalone or is updated along with >>> timecounter calls. Was thinking if we move the lock in timecounter >>> functions, drivers just have to do locking around its operations on >>> cyclecounter. But then another problem I see is there are variation of >>> locking calls like lock_irqsave, lock_bh, write_lock_irqsave (some using >>> rwlock_t). Should this all locking be left to driver only then? >> >> You could have the lock in the struct and protect the inner workings in >> the >> related core functions. >> >> That might remove locking requirements from some of the callers and the >> others still have their own thing around it. > > > For drivers having static/fixed cyclecounter, we can rely only on lock > inside timecounter. > Most of the network drivers update cyclecounter at runtime and they will > have to rely on two locks if > we add one to timecounter. This may not be efficient for them. Also the lock > in timecounter has to be less restrictive (may be seqlock) I guess. > > Cc'd Mellanox list for inputs on this. > > I have started feeling that the current approach of drivers managing the > locks is the right one so better leave the > lock out of timecounter. > I agree here, In mlx5 we rely on our own read/write lock to serialize access to mlx5_clock struct (mlx5 timecounter and cyclecounter). the access is not as simple as lock() call time_counter_API unlock() Sometimes we also explicitly update/adjust timecycles counters with mlx5 specific calculations after we read the timecounter all inside our lock. e.g. @mlx5_ptp_adjfreq() write_lock_irqsave(&clock->lock, flags); timecounter_read(&clock->tc); clock->cycles.mult = neg_adj ? clock->nominal_c_mult - diff : clock->nominal_c_mult + diff; write_unlock_irqrestore(&clock->lock, flags); So i don't think it will be a simple task to have a generic thread safe timecounter API, without the need to specifically adjust it for all driver use-cases. Also as said above, in runtime it is not obvious in which context the timecounter will be accessed irq/soft irq/user. let's keep it as is, and let the driver decide which locking scheme is most suitable for it. Thanks, Saeed. >> Thanks, >> >> tglx > > > -- > To unsubscribe from this list: send the line "unsubscribe linux-rdma" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html From 1585213313259750832@xxx Mon Nov 27 10:07:02 +0000 2017 X-GM-THRID: 1584841375616009291 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread