Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1053174ybf; Thu, 27 Feb 2020 04:15:15 -0800 (PST) X-Google-Smtp-Source: APXvYqwH73gzJjWwZ5HtvjHHlF7SWtnc36OQaTnJ866PlmUBsiLstOToDeAmrrDYmQ4j84DutpWB X-Received: by 2002:aca:cd0e:: with SMTP id d14mr1172515oig.167.1582805715706; Thu, 27 Feb 2020 04:15:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582805715; cv=none; d=google.com; s=arc-20160816; b=VNLsexz6CkBdPDyE5TraRGUGCtbyhHBdjuPwgCsHYC60UgQ2LqD6+j1ssAq8+ak8iC 5V2Cvz0sfQHD7Fzd9iKKKXTgDWgzMR7f8PnyZPzayDRl2DHHxpqLIMrBTI0pKh1aiL88 y+OPkIFt1MiLT9EVCCYB4wKuSlgH6O99swm1e6NXcEaB4xHMGAg1FcyO19Ync0FE8Ycm p8RPAHVC4Vw7WxBebrrROY/+JuKOLCqLk1N9196xQ6kS/Ybk/lM8YIYLmEQRsAWB+6dh I5yyFqEyzi/exJDnGNpn3F0tXzwk1Akuv3zngWufLnEspShYLMGPgL98XPqhr8erHzr+ QfkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:references:in-reply-to:subject:cc:to:from :dkim-signature; bh=j2D82d9yGQCcZdAAoWsJQEf0HtVPlovUAMIiLK8MIQk=; b=Ux6XZArVTmLP/5JGBTZ0b2IUbOuOVml9NrvxWJzdDpoV9M19X96qSsDLbOyE6Ln4kH 7Tsua0WOmbfbM5sksojRkIP8rH8GRiCUhzoYofCMl5ge2tRGz7/VkJypqs0P5Y1w/1u5 qQE+JdTlEZ5Vz6kOdPOH384wDEnfD1da9sApqtF4yt4RaflFt0jDbw0IK+rDqyHWFoWJ QJwDpZ1K63RTzJ11H7iVffyTxOSuTolnkkgd/KPMl8NGNQF8t73K71D16wnlVymRuWnt 3qIxA+CwdUJOk604edO9MtJ7CtygCJl1Ftic+MUDMKlzjFKDJ1EQFpGc6FOyWVtNpoeK iUAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QS8y0DSU; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o6si1165427oic.34.2020.02.27.04.15.03; Thu, 27 Feb 2020 04:15:15 -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=@redhat.com header.s=mimecast20190719 header.b=QS8y0DSU; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728956AbgB0MNh (ORCPT + 99 others); Thu, 27 Feb 2020 07:13:37 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:41424 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728856AbgB0MNh (ORCPT ); Thu, 27 Feb 2020 07:13:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582805615; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j2D82d9yGQCcZdAAoWsJQEf0HtVPlovUAMIiLK8MIQk=; b=QS8y0DSU24DKXydopCF7KrL1NJDuolwX1HiSWuXmO40oi4XQ0SsLaVg2ptCAHwzbPRxm8Q NEwo4T48vBTxrQHc+zmCe0MnXuS9dsbIz661361XjjYN5N0wHOF5gsA8W6f+aTMHUNDvrj pPm6gZb4TRf4sZHyz7m5n7tnO3oXPok= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-236-eJcD63VbNX26U5U5Hu2dWg-1; Thu, 27 Feb 2020 07:13:34 -0500 X-MC-Unique: eJcD63VbNX26U5U5Hu2dWg-1 Received: by mail-wr1-f72.google.com with SMTP id z1so1227677wrs.9 for ; Thu, 27 Feb 2020 04:13:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version:content-transfer-encoding; bh=j2D82d9yGQCcZdAAoWsJQEf0HtVPlovUAMIiLK8MIQk=; b=UxUSKlbeNx6cSsA0ZZAOXlSblTcovn5wIShOIUVPorZGg7ltZMw4R1KQs2ZEtTeBk1 h/dVvOX1XOllXH0z43XGusPbGUrAuFGr3LXMy5y3lmuy+3499Vzc1j9+fubALnhedCJO IGyYAABZaagBNf1DlB7NsI2LGcIrldP/RXq9cIrWxkv47lWRf7qxf+E1Jnb5xFCE7NEZ I43A7vfo7jmhVisxtL1QGPWJIu3nv5f2ViBSfnMoKgkcUBTOF9VAilA8lMuzXfFo501v tomanTy+HOhkD+qC5ewLBvTB7EoEGiIY/iav8F13pvFVRIJzfd+9MOTWOAGI/4SLsy/j crHA== X-Gm-Message-State: APjAAAUDEUlbk8uTYUS7R/wQ7avfyx6sOc/9uBU0nc4vqy8pesOo+xFs 1oGagIGgLeec9JjwhTB1uhnP7dwsri1KpywA1i/TuS6Hzjio15ef8NlENFOUbLORkiu1s/gWhYp aucpDF/Xy6QW4l9JqWeQEAlwr X-Received: by 2002:a5d:4408:: with SMTP id z8mr4580042wrq.321.1582805612554; Thu, 27 Feb 2020 04:13:32 -0800 (PST) X-Received: by 2002:a5d:4408:: with SMTP id z8mr4580014wrq.321.1582805612314; Thu, 27 Feb 2020 04:13:32 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id d7sm7843915wmc.6.2020.02.27.04.13.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2020 04:13:31 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id C43D5180362; Thu, 27 Feb 2020 13:13:29 +0100 (CET) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: Luigi Rizzo Cc: linux-kernel@vger.kernel.org, Masami Hiramatsu , Andrew Morton , Greg KH , naveen.n.rao@linux.ibm.com, ardb@kernel.org, Luigi Rizzo , Paolo Abeni , giuseppe.lettieri@unipi.it, Jesper Dangaard Brouer , mingo@redhat.com, acme@kernel.org, Steven Rostedt , Peter Zijlstra Subject: Re: [PATCH v3 0/2] kstats: kernel metric collector In-Reply-To: References: <20200226135027.34538-1-lrizzo@google.com> <87ftexz93y.fsf@toke.dk> <878skpx7th.fsf@toke.dk> X-Clacks-Overhead: GNU Terry Pratchett Date: Thu, 27 Feb 2020 13:13:29 +0100 Message-ID: <87zhd4ut1y.fsf@toke.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Luigi Rizzo writes: > On Wed, Feb 26, 2020 at 3:11 PM Toke H=C3=B8iland-J=C3=B8rgensen wrote: >> >> Luigi Rizzo writes: >> >> > - the runtime cost and complexity of hooking bpf code is still a bit >> > unclear to me. kretprobe or tracepoints are expensive, I suppose that >> > some lean hook replace register_kretprobe() may exist and the >> > difference from inline annotations would be marginal (we'd still need >> > to put in the hooks around the code we want to time, though, so it >> > wouldn't be a pure bpf solution). Any pointers to this are welcome; >> > Alexei mentioned fentry/fexit and bpf trampolines, but I haven't found >> > an example that lets me do something equivalent to kretprobe (take a >> > timestamp before and one after a function without explicit >> > instrumentation) >> >> As Alexei said, with fentry/fexit the overhead should be on par with >> your example. This functionality is pretty new, though, so I can >> understand why it's not obvious how to do things with it yet :) >> >> I think the best place to look is currently in selftests/bpf in the >> kernel sources. Grep for 'fexit' and 'fentry' in the progs/ subdir. >> test_overhead.c and kfree_skb.c seem to have some examples you may be >> able to work from. > > Thank you for the precise reference, Toke. > I tweaked test_overhead.c to measure (using kstats) the cost of the vario= us > hooks and I can confirm that fentry and fexit are pretty fast. The > following table > shows the p90 runtime of __set_task_comm() at low (100/s) and high (1M/s)= rates: > > 90 percentile of __set_task_comm() runtime > (accuracy: 30ns) > call rate base kprobe kretprobe tracepoint fentry fex= it > 100/sec 270 870 1220 500 400 = 450 > >1M/s 60 120 210 90 > 70 80 > > For high rate operation, the overhead of fentry and fexit is quite good, > even better than tracepoints, and well below the clock's accuracy > (more detailed measurements indicate ~5ns for fentry, ~10ns for fexit). > At very low call rates there is an extra 150-200ns > but that is expected due to the out of line code. Great, thank you for the performance numbers! This is indeed quite good :) -Toke