[PATCH 3/4] drmgr/cpu: add CPU add and remove operation's hooks

20 views
Skip to first unread message

Laurent Dufour

<ldufour@linux.ibm.com>
unread,
Mar 7, 2023, 8:22:19 AM3/7/23
to powerpc-utils-devel@googlegroups.com, tyreld@linux.ibm.com, nathanl@linux.ibm.com
Call drmgr's hooks before and after a CPU add or remove operatoin is done.

Signed-off-by: Laurent Dufour <ldu...@linux.ibm.com>
---
src/drmgr/drslot_chrp_cpu.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/src/drmgr/drslot_chrp_cpu.c b/src/drmgr/drslot_chrp_cpu.c
index d4bd4c5375a9..9915e30254f7 100644
--- a/src/drmgr/drslot_chrp_cpu.c
+++ b/src/drmgr/drslot_chrp_cpu.c
@@ -442,6 +442,9 @@ int drslot_chrp_cpu(void)
return rc;
}

+ if (usr_action == ADD || usr_action == REMOVE)
+ run_hooks(DRC_TYPE_CPU, usr_action, HOOK_PRE);
+
switch (usr_action) {
case ADD:
rc = add_cpus(&dr_info);
@@ -454,6 +457,9 @@ int drslot_chrp_cpu(void)
break;
}

+ if (usr_action == ADD || usr_action == REMOVE)
+ run_hooks(DRC_TYPE_CPU, usr_action, HOOK_POST);
+
free_cpu_drc_info(&dr_info);
return rc;
}
--
2.39.2

Laurent Dufour

<ldufour@linux.ibm.com>
unread,
Mar 7, 2023, 8:22:19 AM3/7/23
to powerpc-utils-devel@googlegroups.com, tyreld@linux.ibm.com, nathanl@linux.ibm.com
Extend the drmgr's hook mechanism for CPU DLPAR add and remove operations.

Add a new hook environment variable "ACTION" to detail the ongoing action.
In the case of the CPU DLPAR operation, this variable will be set to either
"add" or "remove".

The hook is called twice per operation, with PHASE set to PRE before doing
the operation, and set to POST once the operation is done, even if it has
failed. The returned value is ignored for the 2 phases.

The last patch in the series is adding details in the drmgr-hook man page.

Laurent Dufour (4):
drmgr/common: introduce action to string table
drmgr: Add action parameter to the hook mechanism
drmgr/cpu: add CPU add and remove operation's hooks
drmgr: Add CPU hook in the man page

man/drmgr-hooks.8 | 37 ++++++++++++++++++++++++++++++++++---
src/drmgr/common.c | 21 +++++++++++++++++----
src/drmgr/dr.h | 2 +-
src/drmgr/drmig_chrp_pmig.c | 8 ++++----
src/drmgr/drslot_chrp_cpu.c | 6 ++++++
5 files changed, 62 insertions(+), 12 deletions(-)

--
2.39.2

Laurent Dufour

<ldufour@linux.ibm.com>
unread,
Mar 7, 2023, 8:22:20 AM3/7/23
to powerpc-utils-devel@googlegroups.com, tyreld@linux.ibm.com, nathanl@linux.ibm.com
Also fixing few minor typos.

Signed-off-by: Laurent Dufour <ldu...@linux.ibm.com>
---
man/drmgr-hooks.8 | 37 ++++++++++++++++++++++++++++++++++---
1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/man/drmgr-hooks.8 b/man/drmgr-hooks.8
index 621e4f0cb54e..d644d2a7534b 100644
--- a/man/drmgr-hooks.8
+++ b/man/drmgr-hooks.8
@@ -23,7 +23,7 @@ Hook files can be symbolic links to executable files. All the hooks can be store
and linked into multiple directories to provide multiple DRC type's hooks.
.SH ARGUMENTS
.P
-Hooks are called without any arguments but with at least these 2 environment variable set:
+Hooks are called without any arguments but with these environment variables set:
.TP
.BI "DRC_TYPE"
The Dynamic reconfiguration connector type to act upon from the following list:
@@ -32,6 +32,10 @@ The Dynamic reconfiguration connector type to act upon from the following list:
.BI "PHASE"
The phase of the operation from the following list:
.BR check ", " undocheck ", " pre ", " post "."
+.TP
+.BI "ACTION"
+The action in progress from the following list:
+.BR add ", " remove ", " migrate "."
.SH LPAR MIGRATION
.P
When a LPAR migration is initiated the
@@ -57,6 +61,29 @@ phase succeeded, the
phases are triggered. Returned values for these 2 phases are ignored, and the
.B post
phase is triggered even if the LPM operation has failed.
+.P
+The
+.B ACTION
+variable is set always to
+.B migrate
+.SH CPU
+When a CPU DLPAR add or remove operation is initiated, the
+.B pre
+and then
+.B post
+phases are triggered with the
+.B ACTION
+variable set to either
+.B add
+or
+.B remove
+value.
+.P
+Return values for these 2 phases are ignored.
+.P
+The
+.B post
+phase is triggered even if the operation has failed.
.SH ENVIRONMENT
.P
The drmgr's hooks are called while holding the DLPAR lock, so any other
@@ -66,16 +93,20 @@ The hooks standard input
.B STDIN
is redirected to
.I /dev/null
-while STDOUT and STDERR are redirected to pipes.
+while
+.BR STDOUT " and " STDERR
+are redirected to pipes.
The outputs done in these pipes are reported to the end user when a hook has returned an error value and that error value is not ignored (e.g in the LPM, the
.B check
phase but not the
-.BR pre "or " post
+.BR pre " or " post
phase)
.P
Except the variables specified in the ARGUMENTS section, all the environment variables are unset before calling the hook.
.SH FILES
.IR /etc/drmgr.d/pmig/
+.P
+.IR /etc/drmgr.d/cpu/
.SH AUTHOR
Laurent Dufour <ldu...@linux.ibm.com>
.SH SEE ALSO
--
2.39.2

Nathan Lynch

<nathanl@linux.ibm.com>
unread,
Mar 7, 2023, 10:08:41 PM3/7/23
to Laurent Dufour, tyreld@linux.ibm.com, powerpc-utils-devel@googlegroups.com
Laurent Dufour <ldu...@linux.ibm.com> writes:
> Extend the drmgr's hook mechanism for CPU DLPAR add and remove operations.
>
> Add a new hook environment variable "ACTION" to detail the ongoing action.
> In the case of the CPU DLPAR operation, this variable will be set to either
> "add" or "remove".
>
> The hook is called twice per operation, with PHASE set to PRE before doing
> the operation, and set to POST once the operation is done, even if it has
> failed. The returned value is ignored for the 2 phases.

It's hard to see how it's meant to be used. Does drmgr provide the hooks
more information than "some processors are about to be added" or "some
processors may have been removed"?

Laurent Dufour

<ldufour@linux.ibm.com>
unread,
Mar 8, 2023, 5:03:31 AM3/8/23
to Nathan Lynch, tyreld@linux.ibm.com, powerpc-utils-devel@googlegroups.com
I may add a quantity variable.
During the PRE phase it would be set to usr_drc_count, and during the POST
phase, I may try to set it to the actual number of CPU added or removed.

Regarding the usage, one is already identified. It could be used to force
the SMT level once a CPU add operation is done. Saving the actual SMT level
before the add operation is performed and forcing it once the operation is
done.

Nathan Lynch

<nathanl@linux.ibm.com>
unread,
Mar 9, 2023, 8:28:59 AM3/9/23
to Laurent Dufour, tyreld@linux.ibm.com, powerpc-utils-devel@googlegroups.com
I assume this would work by saving the output of 'ppc64_cpu --smt' in
the pre phase, and then running 'ppc64_cpu --smt=X' in the post phase?

I wonder whether that would really be satsifactory for users/apps with
an interest in the SMT configuration. If they're paying attention to CPU
online/offline events from the kernel, which currently onlines all
threads on any added core, then they'll receive a group of online events
immediately followed by a group of offline events for a subset of the
CPUs just onlined. They would have to be aware that there's a window of
time where the SMT mode is inconsistent with their policy.

Is there some reason we can't add to the kernel the ability to specify
the SMT mode for added processors through the existing DLPAR sysfs
interface? Then drmgr could use that directly and avoid onlining threads
only to turn them off again. I suspect that's what we will need to do in
the long term anyway -- not hard to imagine a requirement that
processors *never* run in a non-preferred SMT mode for one reason or
another.

Laurent Dufour

<ldufour@linux.ibm.com>
unread,
Mar 30, 2023, 12:09:54 PM3/30/23
to Nathan Lynch, tyreld@linux.ibm.com, powerpc-utils-devel@googlegroups.com
Beyond the SMT case, it would be interesting to applications to be notified
that a CPU remove operation is about to be done. This is not doable using
the udev events mechanism AFAIK.

Just for this use case, these new hooks are needed.

Nathan Lynch

<nathanl@linux.ibm.com>
unread,
Apr 3, 2023, 5:33:32 PM4/3/23
to Laurent Dufour, tyreld@linux.ibm.com, powerpc-utils-devel@googlegroups.com
OK. I don't think I'm against adding hooks in principle, but I am curious
how much information the payloads will need to contain (e.g. specific CPU
numbers?) to be useful to the consumers.

Laurent Dufour

<ldufour@linux.ibm.com>
unread,
Apr 4, 2023, 3:39:43 AM4/4/23
to Nathan Lynch, tyreld@linux.ibm.com, powerpc-utils-devel@googlegroups.com
If by "specific CPU numbers" you're talking about CPU ids, this will be
hard to provide that.

This patch is providing the number of CPU to be removed, to be added, and
added, as detailed in the man page.

Laurent Dufour

<ldufour@linux.ibm.com>
unread,
Apr 5, 2023, 10:46:13 AM4/5/23
to Nathan Lynch, tyreld@linux.ibm.com, powerpc-utils-devel@googlegroups.com
I'm just realizing that I didn't yet the new series containing the
DRC_COUNT environment variable passed to the CPU add and remove hooks.The
man page will say:

"When the pre phase is called, the DRC_COUNT variable contains the
desired number of CPU to add or remove. When the post phase is called,
DRC_COUNT contains the number of CPU effectively added or removed."

I'll send a V2 series containing these changes.

Laurent Dufour

<ldufour@linux.ibm.com>
unread,
Apr 5, 2023, 11:49:42 AM4/5/23
to powerpc-utils-devel@googlegroups.com, nathanl@linux.ibm.com, tyreld@linux.ibm.com
The drc_type_str and hook_phase_name should be declared as const.
No functional changes.

Fixes: 372599ed28d6 ("drmgr: introduce a DRC type name table")
Fixes: e0928dc5e537 ("drmgr: introducing the hook framework")
Suggested-by: Tyrel Datwyler <tyr...@linux.ibm.com>
Signed-off-by: Laurent Dufour <ldu...@linux.ibm.com>
---
src/drmgr/common.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/drmgr/common.c b/src/drmgr/common.c
index 9cd91d1d627a..7affcb6950b9 100644
--- a/src/drmgr/common.c
+++ b/src/drmgr/common.c
@@ -56,7 +56,7 @@ static long dr_timeout;

#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))

-static char *drc_type_str[] = {
+static const char * const drc_type_str[] = {
[DRC_TYPE_NONE] = "unknwon",
[DRC_TYPE_PCI] = "pci",
[DRC_TYPE_SLOT] = "slot",
@@ -69,7 +69,7 @@ static char *drc_type_str[] = {
[DRC_TYPE_ACC] = "acc",
};

-static char *hook_phase_name[] = {
+static const char * const hook_phase_name[] = {
[HOOK_CHECK] = "check",
[HOOK_UNDOCHECK] = "undocheck",
[HOOK_PRE] = "pre",
--
2.40.0

Laurent Dufour

<ldufour@linux.ibm.com>
unread,
Apr 5, 2023, 11:49:42 AM4/5/23
to powerpc-utils-devel@googlegroups.com, nathanl@linux.ibm.com, tyreld@linux.ibm.com
Add a new hook environment variable "ACTION" to detail the ongoing action.
In the case of the CPU DLPAR operation, this variable will be set to either
"add" or "remove".

The hook is called twice per operation, with PHASE set to PRE before doing
the operation, and set to POST once the operation is done, even if it has
failed. The returned value is ignored for the 2 phases.

The last patch in the series is adding details in the drmgr-hook man page.

Changes since v1:
- Make string tables const (patch 1 and 2)
- Add a DRC_COUNT parameter to the hook.

Laurent Dufour (5):
drmgr/common: make drc_type_str and hook_phase_name const
drmgr/common: drmgr: Add action parameter to the hook mechanism
drmgr/common: add a DRC_COUNT parameter to the hooks
drmgr/cpu: add CPU add and remove operation's hooks
drmgr: Add CPU hook in the man page

man/drmgr-hooks.8 | 52 ++++++++++++++++++++++++++++++++++---
src/drmgr/common.c | 34 ++++++++++++++++++++----
src/drmgr/dr.h | 3 ++-
src/drmgr/drmig_chrp_pmig.c | 8 +++---
src/drmgr/drslot_chrp_cpu.c | 33 +++++++++++++----------
5 files changed, 103 insertions(+), 27 deletions(-)

--
2.40.0

Laurent Dufour

<ldufour@linux.ibm.com>
unread,
Apr 5, 2023, 11:49:43 AM4/5/23
to powerpc-utils-devel@googlegroups.com, nathanl@linux.ibm.com, tyreld@linux.ibm.com
The new DRC_COUNT will be set when running operation on countable items,
like adding or removing CPUs.

For the migration operation, this doesn't make sense and it is set to 0.

Using a signed integer so we can pass signed values, if needed in the
future.

Signed-off-by: Laurent Dufour <ldu...@linux.ibm.com>
---
src/drmgr/common.c | 17 ++++++++++++++---
src/drmgr/dr.h | 3 ++-
src/drmgr/drmig_chrp_pmig.c | 8 ++++----
3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/drmgr/common.c b/src/drmgr/common.c
index 1d1afb94128a..bfec0b9bb966 100644
--- a/src/drmgr/common.c
+++ b/src/drmgr/common.c
@@ -1567,7 +1567,8 @@ enum drc_type to_drc_type(const char *arg)
}

static int run_one_hook(enum drc_type drc_type, enum drmgr_action action,
- enum hook_phase phase, const char *name)
+ enum hook_phase phase, const char *drc_count_str,
+ const char *name)
{
int rc;
pid_t child;
@@ -1613,6 +1614,7 @@ static int run_one_hook(enum drc_type drc_type, enum drmgr_action action,

if (clearenv() ||
setenv("DRC_TYPE", drc_type_str[drc_type], 1) ||
+ setenv("DRC_COUNT", drc_count_str, 1) ||
setenv("ACTION", hook_action_name[action], 1) ||
setenv("PHASE", hook_phase_name[phase], 1)) {
say(ERROR, "Can't set environment variables: %s\n",
@@ -1637,11 +1639,12 @@ static int is_file_or_link(const struct dirent *entry)
* Return 0 if all run script have returned 0 status.
*/
int run_hooks(enum drc_type drc_type, enum drmgr_action action,
- enum hook_phase phase)
+ enum hook_phase phase, int drc_count)
{
int rc = 0, fdd, num, i;
DIR *dir;
struct dirent **entries = NULL;
+ char *drc_count_str;

/* Sanity check */
if (drc_type <= DRC_TYPE_NONE || drc_type >= ARRAY_SIZE(drc_type_str)) {
@@ -1668,6 +1671,12 @@ int run_hooks(enum drc_type drc_type, enum drmgr_action action,
is_file_or_link, versionsort);
closedir(dir);

+ if (asprintf(&drc_count_str, "%d", drc_count) == -1) {
+ say(ERROR, "Can't allocate new string : %s", strerror(errno));
+ free(entries);
+ return -1;
+ }
+
for (i = 0; i < num; i++) {
struct stat st;
struct dirent *entry = entries[i];
@@ -1693,13 +1702,15 @@ int run_hooks(enum drc_type drc_type, enum drmgr_action action,
say(WARN, "Can't stat file %s: %s\n",
name, strerror(errno));
else if (S_ISREG(st.st_mode) && (st.st_mode & S_IXUSR) &&
- run_one_hook(drc_type, action, phase, name))
+ run_one_hook(drc_type, action, phase, drc_count_str,
+ name))
rc = 1;

free(name);
free(entry);
}

+ free(drc_count_str);
free(entries);
return rc;
}
diff --git a/src/drmgr/dr.h b/src/drmgr/dr.h
index 5556f05252e7..60c31c44b7e3 100644
--- a/src/drmgr/dr.h
+++ b/src/drmgr/dr.h
@@ -135,7 +135,8 @@ void print_dlpar_capabilities(void);

void set_output_level(int);

-int run_hooks(enum drc_type drc_type, enum drmgr_action, enum hook_phase phase);
+int run_hooks(enum drc_type drc_type, enum drmgr_action, enum hook_phase phase,
+ int drc_count);

#define DR_BUF_SZ 256

diff --git a/src/drmgr/drmig_chrp_pmig.c b/src/drmgr/drmig_chrp_pmig.c
index f537d9accd36..ab5cee913ce2 100644
--- a/src/drmgr/drmig_chrp_pmig.c
+++ b/src/drmgr/drmig_chrp_pmig.c
@@ -709,9 +709,9 @@ int drmig_chrp_pmig(void)
}

if (usr_action == MIGRATE && (strcmp(usr_p_option, "check") == 0)) {
- rc = run_hooks(drc_type, usr_action, HOOK_CHECK);
+ rc = run_hooks(drc_type, usr_action, HOOK_CHECK, 0);
if (rc)
- run_hooks(drc_type, usr_action, HOOK_UNDOCHECK);
+ run_hooks(drc_type, usr_action, HOOK_UNDOCHECK, 0);
return rc;
}

@@ -736,7 +736,7 @@ int drmig_chrp_pmig(void)
/* Now do the actual migration */
do {
if (usr_action == MIGRATE)
- run_hooks(drc_type, usr_action, HOOK_PRE);
+ run_hooks(drc_type, usr_action, HOOK_PRE, 0);

if (usr_action == MIGRATE)
rc = do_migration(stream_val);
@@ -758,6 +758,6 @@ int drmig_chrp_pmig(void)

/* Post hook is called even if the migration has failed */
if (usr_action == MIGRATE)
- run_hooks(drc_type, usr_action, HOOK_POST);
+ run_hooks(drc_type, usr_action, HOOK_POST, 0);
return rc;
}
--
2.40.0

Laurent Dufour

<ldufour@linux.ibm.com>
unread,
Apr 5, 2023, 11:49:43 AM4/5/23
to powerpc-utils-devel@googlegroups.com, nathanl@linux.ibm.com, tyreld@linux.ibm.com
The user action is now exported to the hook ran by drmgr.
It is exported in the environment variable ACTION.

Signed-off-by: Laurent Dufour <ldu...@linux.ibm.com>
---
src/drmgr/common.c | 21 +++++++++++++++++----
src/drmgr/dr.h | 2 +-
src/drmgr/drmig_chrp_pmig.c | 8 ++++----
3 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/src/drmgr/common.c b/src/drmgr/common.c
index 7affcb6950b9..1d1afb94128a 100644
--- a/src/drmgr/common.c
+++ b/src/drmgr/common.c
@@ -76,6 +76,17 @@ static const char * const hook_phase_name[] = {
[HOOK_POST] = "post",
};

+static const char * const hook_action_name[] = {
+ [NONE] = "none",
+ [ADD] = "add",
+ [REMOVE] = "remove",
+ [QUERY] = "query",
+ [REPLACE] = "replace",
+ [IDENTIFY] = "identify",
+ [MIGRATE] = "migrate",
+ [HIBERNATE] = "hibernate",
+};
+
/**
* set_output level
* @brief Common routine to set the output level
@@ -1555,8 +1566,8 @@ enum drc_type to_drc_type(const char *arg)
return DRC_TYPE_NONE;
}

-static int run_one_hook(enum drc_type drc_type, enum hook_phase phase,
- const char *name)
+static int run_one_hook(enum drc_type drc_type, enum drmgr_action action,
+ enum hook_phase phase, const char *name)
{
int rc;
pid_t child;
@@ -1602,6 +1613,7 @@ static int run_one_hook(enum drc_type drc_type, enum hook_phase phase,

if (clearenv() ||
setenv("DRC_TYPE", drc_type_str[drc_type], 1) ||
+ setenv("ACTION", hook_action_name[action], 1) ||
setenv("PHASE", hook_phase_name[phase], 1)) {
say(ERROR, "Can't set environment variables: %s\n",
strerror(errno));
@@ -1624,7 +1636,8 @@ static int is_file_or_link(const struct dirent *entry)
* Run all executable hooks found in a given directory.
* Return 0 if all run script have returned 0 status.
*/
-int run_hooks(enum drc_type drc_type, enum hook_phase phase)
+int run_hooks(enum drc_type drc_type, enum drmgr_action action,
+ enum hook_phase phase)
{
int rc = 0, fdd, num, i;
DIR *dir;
@@ -1680,7 +1693,7 @@ int run_hooks(enum drc_type drc_type, enum hook_phase phase)
say(WARN, "Can't stat file %s: %s\n",
name, strerror(errno));
else if (S_ISREG(st.st_mode) && (st.st_mode & S_IXUSR) &&
- run_one_hook(drc_type, phase, name))
+ run_one_hook(drc_type, action, phase, name))
rc = 1;

free(name);
diff --git a/src/drmgr/dr.h b/src/drmgr/dr.h
index 5526c29a9460..5556f05252e7 100644
--- a/src/drmgr/dr.h
+++ b/src/drmgr/dr.h
@@ -135,7 +135,7 @@ void print_dlpar_capabilities(void);

void set_output_level(int);

-int run_hooks(enum drc_type drc_type, enum hook_phase phase);
+int run_hooks(enum drc_type drc_type, enum drmgr_action, enum hook_phase phase);

#define DR_BUF_SZ 256

diff --git a/src/drmgr/drmig_chrp_pmig.c b/src/drmgr/drmig_chrp_pmig.c
index f169fa500316..f537d9accd36 100644
--- a/src/drmgr/drmig_chrp_pmig.c
+++ b/src/drmgr/drmig_chrp_pmig.c
@@ -709,9 +709,9 @@ int drmig_chrp_pmig(void)
}

if (usr_action == MIGRATE && (strcmp(usr_p_option, "check") == 0)) {
- rc = run_hooks(drc_type, HOOK_CHECK);
+ rc = run_hooks(drc_type, usr_action, HOOK_CHECK);
if (rc)
- run_hooks(drc_type, HOOK_UNDOCHECK);
+ run_hooks(drc_type, usr_action, HOOK_UNDOCHECK);
return rc;
}

@@ -736,7 +736,7 @@ int drmig_chrp_pmig(void)
/* Now do the actual migration */
do {
if (usr_action == MIGRATE)
- run_hooks(drc_type, HOOK_PRE);
+ run_hooks(drc_type, usr_action, HOOK_PRE);

if (usr_action == MIGRATE)
rc = do_migration(stream_val);
@@ -758,6 +758,6 @@ int drmig_chrp_pmig(void)

/* Post hook is called even if the migration has failed */
if (usr_action == MIGRATE)
- run_hooks(drc_type, HOOK_POST);
+ run_hooks(drc_type, usr_action, HOOK_POST);
return rc;
}
--
2.40.0

Laurent Dufour

<ldufour@linux.ibm.com>
unread,
Apr 5, 2023, 11:49:44 AM4/5/23
to powerpc-utils-devel@googlegroups.com, nathanl@linux.ibm.com, tyreld@linux.ibm.com
Call drmgr's hooks before and after a CPU add or remove operation is done.

At the PRE phase, the DRC_COUNT hook parameter is set to the desired number
of CPU to add or remove. At the POST phase, it is set to the actual number
of CPU added or removed.

Signed-off-by: Laurent Dufour <ldu...@linux.ibm.com>
---
src/drmgr/drslot_chrp_cpu.c | 33 +++++++++++++++++++--------------
1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/src/drmgr/drslot_chrp_cpu.c b/src/drmgr/drslot_chrp_cpu.c
index d4bd4c5375a9..3ef24f433487 100644
--- a/src/drmgr/drslot_chrp_cpu.c
+++ b/src/drmgr/drslot_chrp_cpu.c
@@ -231,14 +231,13 @@ struct dr_node *get_available_cpu(struct dr_info *dr_info)
* @param nr_cpus
* @returns 0 on success, !0 otherwise
*/
-static int add_cpus(struct dr_info *dr_info)
+static int add_cpus(struct dr_info *dr_info, int *count)
{
int rc = -1;
- uint count;
struct dr_node *cpu = NULL;

- count = 0;
- while (count < usr_drc_count) {
+ *count = 0;
+ while (*count < usr_drc_count) {
if (drmgr_timed_out())
break;

@@ -255,10 +254,10 @@ static int add_cpus(struct dr_info *dr_info)
}

fprintf(stdout, "%s\n", cpu->drc_name);
- count++;
+ (*count)++;
}

- say(DEBUG, "Acquired %d of %d requested cpu(s).\n", count,
+ say(DEBUG, "Acquired %d of %d requested cpu(s).\n", *count,
usr_drc_count);
return rc ? 1 : 0;
}
@@ -286,13 +285,13 @@ static int add_cpus(struct dr_info *dr_info)
* @param nr_cpus
* @returns 0 on success, !0 otherwise
*/
-static int remove_cpus(struct dr_info *dr_info)
+static int remove_cpus(struct dr_info *dr_info, int *count)
{
int rc = 0;
- uint count = 0;
struct dr_node *cpu;

- while (count < usr_drc_count) {
+ *count = 0;
+ while (*count < usr_drc_count) {
if (drmgr_timed_out())
break;

@@ -318,10 +317,10 @@ static int remove_cpus(struct dr_info *dr_info)
}

fprintf(stdout, "%s\n", cpu->drc_name);
- count++;
+ (*count)++;
}

- say(DEBUG, "Removed %d of %d requested cpu(s)\n", count,
+ say(DEBUG, "Removed %d of %d requested cpu(s)\n", *count,
usr_drc_count);
return rc;
}
@@ -406,7 +405,7 @@ int valid_cpu_options(void)
int drslot_chrp_cpu(void)
{
struct dr_info dr_info;
- int rc;
+ int rc, count = 0;

if (! cpu_dlpar_capable()) {
say(ERROR, "CPU DLPAR capability is not enabled on this "
@@ -442,18 +441,24 @@ int drslot_chrp_cpu(void)
return rc;
}

+ if (usr_action == ADD || usr_action == REMOVE)
+ run_hooks(DRC_TYPE_CPU, usr_action, HOOK_PRE, usr_drc_count);
+
switch (usr_action) {
case ADD:
- rc = add_cpus(&dr_info);
+ rc = add_cpus(&dr_info, &count);
break;
case REMOVE:
- rc = remove_cpus(&dr_info);
+ rc = remove_cpus(&dr_info, &count);
break;
default:
rc = -1;
break;
}

+ if (usr_action == ADD || usr_action == REMOVE)
+ run_hooks(DRC_TYPE_CPU, usr_action, HOOK_POST, count);
+
free_cpu_drc_info(&dr_info);
return rc;
}
--
2.40.0

Laurent Dufour

<ldufour@linux.ibm.com>
unread,
Apr 5, 2023, 11:49:45 AM4/5/23
to powerpc-utils-devel@googlegroups.com, nathanl@linux.ibm.com, tyreld@linux.ibm.com
Also fixing few minor typos.

Signed-off-by: Laurent Dufour <ldu...@linux.ibm.com>
---
man/drmgr-hooks.8 | 52 ++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 49 insertions(+), 3 deletions(-)

diff --git a/man/drmgr-hooks.8 b/man/drmgr-hooks.8
index 621e4f0cb54e..cd6fd09247e7 100644
--- a/man/drmgr-hooks.8
+++ b/man/drmgr-hooks.8
@@ -23,7 +23,7 @@ Hook files can be symbolic links to executable files. All the hooks can be store
and linked into multiple directories to provide multiple DRC type's hooks.
.SH ARGUMENTS
.P
-Hooks are called without any arguments but with at least these 2 environment variable set:
+Hooks are called without any arguments but with these environment variables set:
.TP
.BI "DRC_TYPE"
The Dynamic reconfiguration connector type to act upon from the following list:
@@ -32,6 +32,13 @@ The Dynamic reconfiguration connector type to act upon from the following list:
.BI "PHASE"
The phase of the operation from the following list:
.BR check ", " undocheck ", " pre ", " post "."
+.TP
+.BI "ACTION"
+The action in progress from the following list:
+.BR add ", " remove ", " migrate "."
+.TP
+.BI "DRC_COUNT"
+The number of impacted items.
.SH LPAR MIGRATION
.P
When a LPAR migration is initiated the
@@ -57,6 +64,41 @@ phase succeeded, the
phases are triggered. Returned values for these 2 phases are ignored, and the
.B post
phase is triggered even if the LPM operation has failed.
+.P
+The
+.B ACTION
+variable is set always to
+.B migrate
+.P
+The DRC_COUNT variable is set to 0.
+.SH CPU
+When a CPU DLPAR add or remove operation is initiated, the
+.B pre
+and then
+.B post
+phases are triggered with the
+.B ACTION
+variable set to either
+.B add
+or
+.B remove
+value.
+.P
+When the
+.B pre
+phase is called, the
+.B DRC_COUNT
+variable contains the desired number of CPU to add or remove. When the
+.B post
+phase is called,
+.B DRC_COUNT
+contains the number of CPU effectively added or removed.
+.P
+Return values for these 2 phases are ignored.
+.P
+The
+.B post
+phase is triggered even if the operation has failed.
.SH ENVIRONMENT
.P
The drmgr's hooks are called while holding the DLPAR lock, so any other
@@ -66,16 +108,20 @@ The hooks standard input
.B STDIN
is redirected to
.I /dev/null
-while STDOUT and STDERR are redirected to pipes.
+while
+.BR STDOUT " and " STDERR
+are redirected to pipes.
The outputs done in these pipes are reported to the end user when a hook has returned an error value and that error value is not ignored (e.g in the LPM, the
.B check
phase but not the
-.BR pre "or " post
+.BR pre " or " post
phase)
.P
Except the variables specified in the ARGUMENTS section, all the environment variables are unset before calling the hook.
.SH FILES
.IR /etc/drmgr.d/pmig/
+.P
+.IR /etc/drmgr.d/cpu/
.SH AUTHOR
Laurent Dufour <ldu...@linux.ibm.com>
.SH SEE ALSO
--
2.40.0

Laurent Dufour

<ldufour@linux.ibm.com>
unread,
May 10, 2023, 11:53:21 AM5/10/23
to powerpc-utils-devel@googlegroups.com, nathanl@linux.ibm.com, tyreld@linux.ibm.com
Hi
It's been more than a month and I have sent this series.
Nobody replied, does that means nobody has any objections, and it's all
good, right?

Laurent Dufour

<ldufour@linux.ibm.com>
unread,
Jun 29, 2023, 11:02:36 AM6/29/23
to tyreld@linux.ibm.com, nathanl@linux.ibm.com, powerpc-utils-devel@googlegroups.com
Hi Tyrel,

Is there any concern with this series?

Cheers,
Laurent.
Reply all
Reply to author
Forward
0 new messages