From patchwork Tue Feb 10 03:45:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 438178 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 274F914012A for ; Tue, 10 Feb 2015 14:48:46 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933075AbbBJDsm (ORCPT ); Mon, 9 Feb 2015 22:48:42 -0500 Received: from mail-pa0-f54.google.com ([209.85.220.54]:43016 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761653AbbBJDqN (ORCPT ); Mon, 9 Feb 2015 22:46:13 -0500 Received: by mail-pa0-f54.google.com with SMTP id kx10so23102026pab.13 for ; Mon, 09 Feb 2015 19:46:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8PBfZXV0ssbM1upVwBl0hAAS0DvVKGeFUTmdMIsp/Rk=; b=dbRCvPAp6KXCcSErvO28HA69bAzxeSl74qmkI3zHXhtIOfJeoVvoBbVMTFrBIU+FNE ji48xoxjONS3+3YKkO8Cz9xh+IPVsG+cL3i2QsjLEHO9x4IXQobRksXIw31QpbiCK77a A7RyTX3fY6lo2OYPVEiTuIxdcu7yiAjkvMRRvxebZb6EYrxuBbva2y84U6nN+VLI6Ose sBVAry/NGflH7BzL8f+uutVEPFBLLcWRM5Tvhu9LQ6mRGEcOLFIQ3yA5YrDR9brcotNj sjyYZL5zHhG+xagUJUEyAFS+PNiFzARpfksdGsnEqKOcUm+SbwXixM5E90cxzrNpyuUe wDLw== X-Gm-Message-State: ALoCoQk0mSTE76HJ4C57pRtu6wr0TPzRX6yVrKUOQL2f2y11rKG5WG9XzWm4A9Wo0vCVoHXlg77u X-Received: by 10.68.211.7 with SMTP id my7mr34779490pbc.115.1423539973145; Mon, 09 Feb 2015 19:46:13 -0800 (PST) Received: from localhost.localdomain ([12.229.56.227]) by mx.google.com with ESMTPSA id fu14sm17888443pad.44.2015.02.09.19.46.12 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 09 Feb 2015 19:46:12 -0800 (PST) From: Alexei Starovoitov To: Steven Rostedt Cc: Ingo Molnar , Namhyung Kim , Arnaldo Carvalho de Melo , Jiri Olsa , Masami Hiramatsu , linux-api@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 linux-trace 2/8] tracing: allow eBPF programs to call ktime_get_ns() Date: Mon, 9 Feb 2015 19:45:55 -0800 Message-Id: <1423539961-21792-3-git-send-email-ast@plumgrid.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1423539961-21792-1-git-send-email-ast@plumgrid.com> References: <1423539961-21792-1-git-send-email-ast@plumgrid.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org bpf_ktime_get_ns() is used by programs to compue time delta between events or as a timestamp Signed-off-by: Alexei Starovoitov --- include/uapi/linux/bpf.h | 1 + kernel/trace/bpf_trace.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index d73d7d0abe6e..ecae21e58ba3 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -169,6 +169,7 @@ enum bpf_func_id { BPF_FUNC_fetch_u16, /* u16 bpf_fetch_u16(void *unsafe_ptr) */ BPF_FUNC_fetch_u8, /* u8 bpf_fetch_u8(void *unsafe_ptr) */ BPF_FUNC_probe_memcmp, /* int bpf_probe_memcmp(unsafe_ptr, safe_ptr, size) */ + BPF_FUNC_ktime_get_ns, /* u64 bpf_ktime_get_ns(void) */ __BPF_FUNC_MAX_ID, }; diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index ec065e0a364e..e3196266b72f 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -69,6 +69,11 @@ static u64 bpf_probe_memcmp(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5) return -1; } +static u64 bpf_ktime_get_ns(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5) +{ + return ktime_get_ns(); +} + static struct bpf_func_proto tp_prog_funcs[] = { #define FETCH(SIZE) \ [BPF_FUNC_fetch_##SIZE] = { \ @@ -90,6 +95,11 @@ static struct bpf_func_proto tp_prog_funcs[] = { .arg2_type = ARG_PTR_TO_STACK, .arg3_type = ARG_CONST_STACK_SIZE, }, + [BPF_FUNC_ktime_get_ns] = { + .func = bpf_ktime_get_ns, + .gpl_only = true, + .ret_type = RET_INTEGER, + }, }; static const struct bpf_func_proto *tp_prog_func_proto(enum bpf_func_id func_id)