From 4d28f29b6c9d5ba754eef584c7866c3ffee1adbc Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Fri, 20 Feb 2009 14:28:00 -0800 Subject: [PATCH] Update profile scripts with additional upcalls for fine grained profiling --- module/zpios/include/zpios-ctl.h | 14 ++++++++++---- module/zpios/zpios.c | 28 ++++++++++++++++------------ scripts/zpios.sh | 30 +++++++++++++++++------------- 3 files changed, 43 insertions(+), 29 deletions(-) diff --git a/module/zpios/include/zpios-ctl.h b/module/zpios/include/zpios-ctl.h index 767fdfdb15..abe4b814bf 100644 --- a/module/zpios/include/zpios-ctl.h +++ b/module/zpios/include/zpios-ctl.h @@ -58,10 +58,16 @@ #define ZPIOS_NAME_SIZE 16 #define ZPIOS_PATH_SIZE 128 -#define PHASE_PRE "pre" -#define PHASE_POST "post" -#define PHASE_WRITE "write" -#define PHASE_READ "read" +#define PHASE_PRE_RUN "pre-run" +#define PHASE_PRE_CREATE "pre-create" +#define PHASE_PRE_WRITE "pre-write" +#define PHASE_PRE_READ "pre-read" +#define PHASE_PRE_REMOVE "pre-remove" +#define PHASE_POST_RUN "post-run" +#define PHASE_POST_CREATE "post-create" +#define PHASE_POST_WRITE "post-write" +#define PHASE_POST_READ "post-read" +#define PHASE_POST_REMOVE "post-remove" #define ZPIOS_CFG_MAGIC 0x87237190U typedef struct zpios_cfg { diff --git a/module/zpios/zpios.c b/module/zpios/zpios.c index 9b3ab28b90..7d170d17ee 100644 --- a/module/zpios/zpios.c +++ b/module/zpios/zpios.c @@ -29,7 +29,7 @@ * * CDDL HEADER END * - * Kernel PIOS DMU implemenation originally derived from PIOS test code. + * Kernel PIOS DMU implementation originally derived from PIOS test code. * Character control interface derived from SPL code. */ @@ -63,7 +63,7 @@ int zpios_upcall(char *path, char *phase, run_args_t *run_args, int rc) char thread_delay[16], flags[16], result[8]; char *argv[16], *envp[4]; - if (strlen(path) == 0) + if ((path == NULL) || (strlen(path) == 0)) return -ENOENT; snprintf(id, 15, "%d", run_args->id); @@ -96,7 +96,7 @@ int zpios_upcall(char *path, char *phase, run_args_t *run_args, int rc) argv[14] = result; argv[15] = NULL; - /* Passing environment for userspace upcall */ + /* Passing environment for user space upcall */ envp[0] = "HOME=/"; envp[1] = "TERM=linux"; envp[2] = "PATH=/sbin:/usr/sbin:/bin:/usr/bin"; @@ -174,6 +174,7 @@ zpios_dmu_setup(run_args_t *run_args) uint64_t obj = 0ULL; int i, rc = 0; + (void)zpios_upcall(run_args->pre, PHASE_PRE_CREATE, run_args, 0); t->start = current_kernel_time(); rc = dmu_objset_open(run_args->pool, DMU_OST_ZFS, DS_MODE_USER, &os); @@ -225,6 +226,7 @@ zpios_dmu_setup(run_args_t *run_args) out: t->stop = current_kernel_time(); t->delta = timespec_sub(t->stop, t->start); + (void)zpios_upcall(run_args->post, PHASE_POST_CREATE, run_args, rc); return rc; } @@ -352,6 +354,7 @@ zpios_remove_objects(run_args_t *run_args) zpios_region_t *region; int rc = 0, i; + (void)zpios_upcall(run_args->pre, PHASE_PRE_REMOVE, run_args, 0); t->start = current_kernel_time(); if (run_args->flags & DMU_REMOVE) { @@ -382,6 +385,7 @@ zpios_remove_objects(run_args_t *run_args) t->stop = current_kernel_time(); t->delta = timespec_sub(t->stop, t->start); + (void)zpios_upcall(run_args->post, PHASE_POST_REMOVE, run_args, rc); } static void @@ -665,8 +669,6 @@ zpios_threads_run(run_args_t *run_args) zpios_time_t *tr = &(run_args->stats.rd_time); int i, rc = 0, tc = run_args->thread_count; - zpios_upcall(run_args->pre, PHASE_PRE, run_args, 0); - tsks = kmem_zalloc(sizeof(struct task_struct *) * tc, KM_SLEEP); if (tsks == NULL) { rc = -ENOMEM; @@ -709,7 +711,7 @@ zpios_threads_run(run_args_t *run_args) tt->start = current_kernel_time(); /* Wake up all threads for write phase */ - zpios_upcall(run_args->pre, PHASE_WRITE, run_args, 0); + (void)zpios_upcall(run_args->pre, PHASE_PRE_WRITE, run_args, 0); for (i = 0; i < tc; i++) wake_up_process(tsks[i]); @@ -717,6 +719,7 @@ zpios_threads_run(run_args_t *run_args) tw->start = current_kernel_time(); wait_event(run_args->waitq, zpios_thread_done(run_args)); tw->stop = current_kernel_time(); + (void)zpios_upcall(run_args->post, PHASE_POST_WRITE, run_args, rc); for (i = 0; i < tc; i++) { thr = run_args->threads[i]; @@ -731,7 +734,6 @@ zpios_threads_run(run_args_t *run_args) mutex_exit(&thr->lock); } - zpios_upcall(run_args->post, PHASE_WRITE, run_args, rc); if (rc) { /* Wake up all threads and tell them to exit */ for (i = 0; i < tc; i++) { @@ -750,7 +752,7 @@ zpios_threads_run(run_args_t *run_args) mutex_exit(&run_args->lock_ctl); /* Wake up all threads for read phase */ - zpios_upcall(run_args->pre, PHASE_READ, run_args, 0); + (void)zpios_upcall(run_args->pre, PHASE_PRE_READ, run_args, 0); for (i = 0; i < tc; i++) wake_up_process(tsks[i]); @@ -758,6 +760,7 @@ zpios_threads_run(run_args_t *run_args) tr->start = current_kernel_time(); wait_event(run_args->waitq, zpios_thread_done(run_args)); tr->stop = current_kernel_time(); + (void)zpios_upcall(run_args->post, PHASE_POST_READ, run_args, rc); for (i = 0; i < tc; i++) { thr = run_args->threads[i]; @@ -771,8 +774,6 @@ zpios_threads_run(run_args_t *run_args) run_args->stats.rd_chunks += thr->stats.rd_chunks; mutex_exit(&thr->lock); } - - zpios_upcall(run_args->post, PHASE_READ, run_args, rc); out: tt->stop = current_kernel_time(); tt->delta = timespec_sub(tt->stop, tt->start); @@ -782,8 +783,6 @@ out: cleanup: kmem_free(tsks, sizeof(struct task_struct *) * tc); cleanup2: - zpios_upcall(run_args->post, PHASE_POST, run_args, rc); - /* Returns first encountered thread error (if any) */ return rc; @@ -844,6 +843,8 @@ zpios_do_one_run(struct file *file, zpios_cmd_t *kcmd, return -ENOSPC; } + (void)zpios_upcall(kcmd->cmd_pre, PHASE_PRE_RUN, run_args, 0); + rc = zpios_setup_run(&run_args, kcmd, file); if (rc) return rc; @@ -867,6 +868,9 @@ zpios_do_one_run(struct file *file, zpios_cmd_t *kcmd, cleanup: zpios_cleanup_run(run_args); + + (void)zpios_upcall(kcmd->cmd_post, PHASE_POST_RUN, run_args, 0); + return rc; } diff --git a/scripts/zpios.sh b/scripts/zpios.sh index 4188a8883b..ed7de35df0 100755 --- a/scripts/zpios.sh +++ b/scripts/zpios.sh @@ -117,30 +117,34 @@ cat > ${PROFILE_ZPIOS_LOG}/zpios-config.sh << EOF # Zpios Profiling Configuration # -KERNEL_BIN="/lib/modules/`uname -r`/kernel/" -SPL_BIN="${SPLBUILD}/module/" -ZFS_BIN="${TOPDIR}/module/" +PROFILE_ZPIOS_LOG=/tmp/zpios/${ZPOOL_CONFIG}+${ZPIOS_TEST_ARG}+${DATE} +PROFILE_ZPIOS_PRE=${TOPDIR}/scripts/zpios-profile/zpios-profile-pre.sh +PROFILE_ZPIOS_POST=${TOPDIR}/scripts/zpios-profile/zpios-profile-post.sh +PROFILE_ZPIOS_USER=${TOPDIR}/scripts/zpios-profile/zpios-profile.sh +PROFILE_ZPIOS_PIDS=${TOPDIR}/scripts/zpios-profile/zpios-profile-pids.sh +PROFILE_ZPIOS_DISK=${TOPDIR}/scripts/zpios-/profile/zpios-profile-disk.sh -PROFILE_ZPIOS_BIN=${TOPDIR}/scripts/zpios-profile/zpios-profile.sh -PROFILE_ZPIOS_PIDS_BIN=${TOPDIR}/scripts/zpios-profile/zpios-profile-pids.sh -PROFILE_ZPIOS_DISK_BIN=${TOPDIR}/scripts/zpios-/profile/zpios-profile-disk.sh +OPROFILE_KERNEL_BIN="/boot/vmlinux-`uname -r`" +OPROFILE_KERNEL_BIN_DIR="/lib/modules/`uname -r`/kernel/" +OPROFILE_SPL_BIN_DIR="${SPLBUILD}/module/" +OPROFILE_ZFS_BIN_DIR="${TOPDIR}/module/" EOF } zpios_profile_start() { - PROFILE_ZPIOS_PRE=${TOPDIR}/scripts/zpios-profile/zpios-profile-pre.sh - PROFILE_ZPIOS_POST=${TOPDIR}/scripts/zpios-profile/zpios-profile-post.sh PROFILE_ZPIOS_LOG=/tmp/zpios/${ZPOOL_CONFIG}+${ZPIOS_TEST_ARG}+${DATE} + + mkdir -p ${PROFILE_ZPIOS_LOG} + zpios_profile_config + . ${PROFILE_ZPIOS_LOG}/zpios-config.sh + ZPIOS_OPTIONS="${ZPIOS_OPTIONS} --log=${PROFILE_ZPIOS_LOG}" ZPIOS_OPTIONS="${ZPIOS_OPTIONS} --prerun=${PROFILE_ZPIOS_PRE}" ZPIOS_OPTIONS="${ZPIOS_OPTIONS} --postrun=${PROFILE_ZPIOS_POST}" - mkdir -p ${PROFILE_ZPIOS_LOG} - zpios_profile_config - - /usr/bin/opcontrol --init || exit 1 - /usr/bin/opcontrol --setup --vmlinux=/boot/vmlinux || exit 1 + /usr/bin/opcontrol --init + /usr/bin/opcontrol --setup --vmlinux=${OPROFILE_KERNEL_BIN} } zpios_profile_stop() {