From patchwork Wed Oct 14 12:41:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 54929 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by patches.linaro.org (Postfix) with ESMTPS id 0B88D23012 for ; Wed, 14 Oct 2015 12:44:51 +0000 (UTC) Received: by wicgb1 with SMTP id gb1sf25990955wic.3 for ; Wed, 14 Oct 2015 05:44:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-type:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe; bh=Y0xBmNpNnLKz0ZC3O7eYrQzMQcLpQxmj5NaRa/1lI+Q=; b=JzUNwjeLUsxUgEI2nisGRTvKjS03/52w/ArLwfQWwK45cCm/Rd74w2xoS2ckOUEKYi HrkHq34eVJm1EHUIlcsXXoXI/ISEzQNdCm/t/+lbrcgtXVqDL0qpMtO9DXsOjtyu0851 b4zvuc4PM/JJxq9B5Yd/TNHuXhRlZP51P8i+IZ3u1tJrbtEGAgbJyeuXoIrPbwq4B/wL nAXsLjy8uujIKsneNBWpZMgTRNLL50MKsWB7kFR9zbM/lWc+U76PATIG1lQD86yt9NE7 L1vzOVMk+0oR+MwdC2v+QPv+spYSusNRGAPJKfofwQmywhEpz3tXjdTCVM1lVeuWnpqS PmJw== X-Gm-Message-State: ALoCoQn/thNTe/ga01XteiT5JHAhO1FXPyWGXtuSk9wvzj9etl8QGO0NES7zTad8hepZmJI8SMj1 X-Received: by 10.180.184.164 with SMTP id ev4mr827293wic.3.1444826690309; Wed, 14 Oct 2015 05:44:50 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.158.146 with SMTP id h140ls35410lfe.108.gmail; Wed, 14 Oct 2015 05:44:50 -0700 (PDT) X-Received: by 10.25.143.72 with SMTP id r69mr989093lfd.65.1444826690126; Wed, 14 Oct 2015 05:44:50 -0700 (PDT) Received: from mail-lb0-f177.google.com (mail-lb0-f177.google.com. [209.85.217.177]) by mx.google.com with ESMTPS id e2si5444107lbp.39.2015.10.14.05.44.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Oct 2015 05:44:50 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) client-ip=209.85.217.177; Received: by lbbpp2 with SMTP id pp2so15987667lbb.0 for ; Wed, 14 Oct 2015 05:44:50 -0700 (PDT) X-Received: by 10.112.135.9 with SMTP id po9mr1533370lbb.56.1444826689984; Wed, 14 Oct 2015 05:44:49 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp2710628lbq; Wed, 14 Oct 2015 05:44:49 -0700 (PDT) X-Received: by 10.68.69.17 with SMTP id a17mr3623011pbu.10.1444826686051; Wed, 14 Oct 2015 05:44:46 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k12si13076528pbq.64.2015.10.14.05.44.45; Wed, 14 Oct 2015 05:44:46 -0700 (PDT) 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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753738AbbJNMon (ORCPT + 30 others); Wed, 14 Oct 2015 08:44:43 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:27871 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753663AbbJNMnF (ORCPT ); Wed, 14 Oct 2015 08:43:05 -0400 Received: from 172.24.1.49 (EHLO szxeml425-hub.china.huawei.com) ([172.24.1.49]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BOX06058; Wed, 14 Oct 2015 20:42:42 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml425-hub.china.huawei.com (10.82.67.180) with Microsoft SMTP Server id 14.3.235.1; Wed, 14 Oct 2015 20:42:31 +0800 From: Wang Nan To: , , CC: , , , , , , , , , , , , Wang Nan , Arnaldo Carvalho de Melo Subject: [PATCH 23/31] bpf tools: Add helper function for updating bpf maps elements Date: Wed, 14 Oct 2015 12:41:34 +0000 Message-ID: <1444826502-49291-24-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1444826502-49291-1-git-send-email-wangnan0@huawei.com> References: <1444826502-49291-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020203.561E4DC2.0267, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: e6e5f9dd73ddfdd67ea22f3ebcadf983 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: wangnan0@huawei.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: He Kuang Add helper function bpf_map_update_elem() which calls sys_bpf syscall to update elements in bpf maps. Signed-off-by: Wang Nan Signed-off-by: He Kuang Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: Brendan Gregg Cc: Daniel Borkmann Cc: David Ahern Cc: He Kuang Cc: Jiri Olsa Cc: Kaixu Xia Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Zefan Li Cc: pi3orama@163.com Link: http://lkml.kernel.org/n/ebpf-yflv9p2x75ht7okavpk97m4g@git.kernel.org --- tools/lib/bpf/bpf.c | 14 ++++++++++++++ tools/lib/bpf/bpf.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index a633105..5bdc6ea 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -83,3 +83,17 @@ int bpf_load_program(enum bpf_prog_type type, struct bpf_insn *insns, log_buf[0] = 0; return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); } + +int bpf_map_update_elem(int fd, void *key, void *value, + u64 flags) +{ + union bpf_attr attr; + + bzero(&attr, sizeof(attr)); + attr.map_fd = fd; + attr.key = ptr_to_u64(key); + attr.value = ptr_to_u64(value); + attr.flags = flags; + + return sys_bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr)); +} diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index 854b736..a764655 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h @@ -20,4 +20,6 @@ int bpf_load_program(enum bpf_prog_type type, struct bpf_insn *insns, u32 kern_version, char *log_buf, size_t log_buf_sz); +int bpf_map_update_elem(int fd, void *key, void *value, + u64 flags); #endif