From 0dd2167a1daf0a5e8b8cae75d3b647b7153ae876 Mon Sep 17 00:00:00 2001 From: Mateusz Starzyk Date: Mon, 4 Jun 2018 15:08:33 +0100 Subject: [PATCH] resctrl: allow monitoring stop for non-existent pids. Change-Id: I70531871258d554c6af138f77f7ec27293c115d9 Signed-off-by: Mateusz Starzyk --- lib/resctrl_alloc.c | 12 +++++++----- lib/resctrl_monitoring.c | 6 ++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/resctrl_alloc.c b/lib/resctrl_alloc.c index 1432ef78..d1c966e4 100644 --- a/lib/resctrl_alloc.c +++ b/lib/resctrl_alloc.c @@ -756,10 +756,8 @@ resctrl_alloc_task_validate(const pid_t task) memset(buf, 0, sizeof(buf)); snprintf(buf, sizeof(buf)-1, "/proc/%d", (int)task); - if (access(buf, F_OK) != 0) { - LOG_ERROR("Task %d does not exist!\n", (int)task); + if (access(buf, F_OK) != 0) return PQOS_RETVAL_ERROR; - } return PQOS_RETVAL_OK; } @@ -772,8 +770,10 @@ resctrl_alloc_task_write(const unsigned class_id, const pid_t task) /* Check if task exists */ ret = resctrl_alloc_task_validate(task); - if (ret != PQOS_RETVAL_OK) + if (ret != PQOS_RETVAL_OK) { + LOG_ERROR("Task %d does not exist!\n", (int)task); return PQOS_RETVAL_PARAM; + } /* Open resctrl tasks file */ fd = resctrl_alloc_fopen(class_id, rctl_tasks, "w"); @@ -867,8 +867,10 @@ resctrl_alloc_task_search(unsigned *class_id, /* Check if task exists */ ret = resctrl_alloc_task_validate(task); - if (ret != PQOS_RETVAL_OK) + if (ret != PQOS_RETVAL_OK) { + LOG_ERROR("Task %d does not exist!\n", (int)task); return PQOS_RETVAL_PARAM; + } /* Get number of COS */ ret = resctrl_alloc_get_grps_num(cap, &max_cos); diff --git a/lib/resctrl_monitoring.c b/lib/resctrl_monitoring.c index c128f910..4e1c3c0b 100644 --- a/lib/resctrl_monitoring.c +++ b/lib/resctrl_monitoring.c @@ -910,6 +910,12 @@ resctrl_mon_stop(struct pqos_mon_data *group) for (i = 0; i < group->tid_nr; i++) { const pid_t tid = group->tid_map[i]; + if (resctrl_alloc_task_validate(tid) != + PQOS_RETVAL_OK) { + LOG_DEBUG("resctrl_mon_stop: Skipping " + "non-existant PID: %d\n", tid); + continue; + } ret = resctrl_mon_assoc_set_pid(tid, NULL); if (ret != PQOS_RETVAL_OK) goto resctrl_mon_stop_exit;