From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933097AbeAIPhP (ORCPT + 1 other); Tue, 9 Jan 2018 10:37:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38787 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933011AbeAIPhN (ORCPT ); Tue, 9 Jan 2018 10:37:13 -0500 From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , David Ahern , Andi Kleen , Alexander Shishkin , Peter Zijlstra Subject: [PATCH 31/49] tools lib fd array: Introduce fdarray__add_clone function Date: Tue, 9 Jan 2018 16:35:04 +0100 Message-Id: <20180109153522.14116-32-jolsa@kernel.org> In-Reply-To: <20180109153522.14116-1-jolsa@kernel.org> References: <20180109153522.14116-1-jolsa@kernel.org> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 09 Jan 2018 15:37:13 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Adding fdarray__add_clone to be able to copy/clone a specific entry from fdarray struct. It will be useful when separating event maps for specific threads. Link: http://lkml.kernel.org/n/tip-0r9rtn1bii1iaggumlgkyxqk@git.kernel.org Signed-off-by: Jiri Olsa --- tools/lib/api/fd/array.c | 17 +++++++++++++++++ tools/lib/api/fd/array.h | 1 + 2 files changed, 18 insertions(+) diff --git a/tools/lib/api/fd/array.c b/tools/lib/api/fd/array.c index b0a035fc87b3..cd458b46f61b 100644 --- a/tools/lib/api/fd/array.c +++ b/tools/lib/api/fd/array.c @@ -84,6 +84,23 @@ int fdarray__add(struct fdarray *fda, int fd, short revents) return pos; } +int fdarray__add_clone(struct fdarray *fda, int pos, struct fdarray *base) +{ + struct pollfd *entry; + int npos; + + if (pos >= base->nr) + return -EINVAL; + + entry = &base->entries[pos]; + + npos = fdarray__add(fda, entry->fd, entry->events); + if (npos >= 0) + fda->priv[npos] = base->priv[pos]; + + return npos; +} + int fdarray__filter(struct fdarray *fda, short revents, void (*entry_destructor)(struct fdarray *fda, int fd, void *arg), void *arg) diff --git a/tools/lib/api/fd/array.h b/tools/lib/api/fd/array.h index b39557d1a88f..06e89d099b1e 100644 --- a/tools/lib/api/fd/array.h +++ b/tools/lib/api/fd/array.h @@ -34,6 +34,7 @@ struct fdarray *fdarray__new(int nr_alloc, int nr_autogrow); void fdarray__delete(struct fdarray *fda); int fdarray__add(struct fdarray *fda, int fd, short revents); +int fdarray__add_clone(struct fdarray *fda, int pos, struct fdarray *base); int fdarray__poll(struct fdarray *fda, int timeout); int fdarray__filter(struct fdarray *fda, short revents, void (*entry_destructor)(struct fdarray *fda, int fd, void *arg), -- 2.13.6