Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp717390ybp; Fri, 4 Oct 2019 03:58:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqzMpWiCihseNYktuq/8d2UTZZ/gKsDo/fXDxf2DQhAvdlXmOvgOzLoE3bKp5yv2bbMRu76j X-Received: by 2002:aa7:d611:: with SMTP id c17mr14792786edr.196.1570186725790; Fri, 04 Oct 2019 03:58:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570186725; cv=none; d=google.com; s=arc-20160816; b=adLxTHz2cr8D/tIdMAQajCygfcIisoKkt9kekzdsjF3vigVFf6b+RR944r1bPfnRqo 7HxlWudce/gXEi+N0Z1fg4GgnsB+EHszaw5tno5JpDTGiKAl0gKEVed01ojjqQmtWLFO KwHzLqoeZrIC6TFz6HG0LTTX53wOy5bD4jLbDfrBrYeQozBN1CR6bPWn4JrG8JTFcUzo 8VaO7gj0gZB8DI/swK3xYg21irTBk4koryD1QsFWTvn9bCUzXBimcO/EzmvGWs21qw/+ b8es5whIud1VVJzoNgfexwGtm42HO+otw7G7taeFSFeLStGeTPwS4ar2ZGmGh1V0u1C+ fOxg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=jlERnmeokJwx85ePAounXiEip9NEJvFlea3Zzk1+qPY=; b=kewLkmGJmf+pW5vSk5xhcT502plqGfQdq424JgWtzhu5XwjxaKudP3FRRwrB96ofPC VkP73RA9PewFDMFZUl7UYO5LMr5FuDuaZy8Mf7Wl4/bwq77V0/EpxU8DYz+rGrmx8Bg2 0ecRQfOHHAR1a+sO02zeQkVJAE1njj9a0zQFoKXabVgKmNM0SuvhS9ADcuutzbUz5Ddh oaMfUv68IpNbuVN0HyFqansgrP9HULtoc4/hGAUClGsmV5kpm2K3WwYE9aEtJlTk78Ik HIuMary4tz0QaMH7gWWkzY64YVOD2tsHNNZc102DbNn53TnDU/NwDC5ACQaCylkKL6J6 6Cfw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c20si2789926ejs.197.2019.10.04.03.58.20; Fri, 04 Oct 2019 03:58:45 -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; Authentication-Results: mx.google.com; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730476AbfJDK6I (ORCPT + 99 others); Fri, 4 Oct 2019 06:58:08 -0400 Received: from mx2.suse.de ([195.135.220.15]:55162 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729065AbfJDK6G (ORCPT ); Fri, 4 Oct 2019 06:58:06 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 56368AD12; Fri, 4 Oct 2019 10:58:04 +0000 (UTC) From: =?UTF-8?q?Michal=20Koutn=C3=BD?= To: cgroups@vger.kernel.org Cc: Tejun Heo , linux-kernel@vger.kernel.org, Li Zefan , Johannes Weiner Subject: [PATCH 3/5] selftests: cgroup: Simplify task self migration Date: Fri, 4 Oct 2019 12:57:41 +0200 Message-Id: <20191004105743.363-4-mkoutny@suse.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191004105743.363-1-mkoutny@suse.com> References: <20191004105743.363-1-mkoutny@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Simplify task migration by being oblivious about its PID during migration. This allows to easily migrate individual threads as well. This change brings no functional change and prepares grounds for thread granularity migrating tests. Signed-off-by: Michal Koutný --- tools/testing/selftests/cgroup/cgroup_util.c | 16 +++++++++++----- tools/testing/selftests/cgroup/cgroup_util.h | 4 +++- tools/testing/selftests/cgroup/test_freezer.c | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/cgroup/cgroup_util.c b/tools/testing/selftests/cgroup/cgroup_util.c index bdb69599c4bd..f6573eac1365 100644 --- a/tools/testing/selftests/cgroup/cgroup_util.c +++ b/tools/testing/selftests/cgroup/cgroup_util.c @@ -282,10 +282,12 @@ int cg_enter(const char *cgroup, int pid) int cg_enter_current(const char *cgroup) { - char pidbuf[64]; + return cg_write(cgroup, "cgroup.procs", "0"); +} - snprintf(pidbuf, sizeof(pidbuf), "%d", getpid()); - return cg_write(cgroup, "cgroup.procs", pidbuf); +int cg_enter_current_thread(const char *cgroup) +{ + return cg_write(cgroup, "cgroup.threads", "0"); } int cg_run(const char *cgroup, @@ -410,11 +412,15 @@ int set_oom_adj_score(int pid, int score) return 0; } -char proc_read_text(int pid, const char *item, char *buf, size_t size) +ssize_t proc_read_text(int pid, bool thread, const char *item, char *buf, size_t size) { char path[PATH_MAX]; - snprintf(path, sizeof(path), "/proc/%d/%s", pid, item); + if (!pid) + snprintf(path, sizeof(path), "/proc/%s/%s", + thread ? "thread-self" : "self", item); + else + snprintf(path, sizeof(path), "/proc/%d/%s", pid, item); return read_text(path, buf, size); } diff --git a/tools/testing/selftests/cgroup/cgroup_util.h b/tools/testing/selftests/cgroup/cgroup_util.h index c72f28046bfa..27ff21d82af1 100644 --- a/tools/testing/selftests/cgroup/cgroup_util.h +++ b/tools/testing/selftests/cgroup/cgroup_util.h @@ -1,4 +1,5 @@ /* SPDX-License-Identifier: GPL-2.0 */ +#include #include #define PAGE_SIZE 4096 @@ -35,6 +36,7 @@ extern int cg_run(const char *cgroup, void *arg); extern int cg_enter(const char *cgroup, int pid); extern int cg_enter_current(const char *cgroup); +extern int cg_enter_current_thread(const char *cgroup); extern int cg_run_nowait(const char *cgroup, int (*fn)(const char *cgroup, void *arg), void *arg); @@ -45,4 +47,4 @@ extern int is_swap_enabled(void); extern int set_oom_adj_score(int pid, int score); extern int cg_wait_for_proc_count(const char *cgroup, int count); extern int cg_killall(const char *cgroup); -extern char proc_read_text(int pid, const char *item, char *buf, size_t size); +extern ssize_t proc_read_text(int pid, bool thread, const char *item, char *buf, size_t size); diff --git a/tools/testing/selftests/cgroup/test_freezer.c b/tools/testing/selftests/cgroup/test_freezer.c index 8219a30853d2..5896e35168cd 100644 --- a/tools/testing/selftests/cgroup/test_freezer.c +++ b/tools/testing/selftests/cgroup/test_freezer.c @@ -648,7 +648,7 @@ static int proc_check_stopped(int pid) char buf[PAGE_SIZE]; int len; - len = proc_read_text(pid, "stat", buf, sizeof(buf)); + len = proc_read_text(pid, 0, "stat", buf, sizeof(buf)); if (len == -1) { debug("Can't get %d stat\n", pid); return -1; -- 2.21.0