From fd3fdbcc7f22554ce010b4a8f31113c5cbf20065 Mon Sep 17 00:00:00 2001 From: wangdi Date: Thu, 19 Oct 2006 09:10:49 +0000 Subject: [PATCH] Branch: b_new_cmd add mdd procfs support to profile mdd ops --- lustre/mdd/Makefile.in | 2 +- lustre/mdd/mdd_handler.c | 12 +++- lustre/mdd/mdd_internal.h | 12 ++++ lustre/mdd/mdd_lproc.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 lustre/mdd/mdd_lproc.c diff --git a/lustre/mdd/Makefile.in b/lustre/mdd/Makefile.in index 7872610..2328054 100644 --- a/lustre/mdd/Makefile.in +++ b/lustre/mdd/Makefile.in @@ -1,5 +1,5 @@ MODULES := mdd -mdd-objs := mdd_handler.o mdd_lov.o mdd_orphans.o +mdd-objs := mdd_handler.o mdd_lov.o mdd_orphans.o mdd_lproc.o EXTRA_PRE_CFLAGS := -I@LINUX@/fs -I@LUSTRE@ -I@LUSTRE@/ldiskfs diff --git a/lustre/mdd/mdd_handler.c b/lustre/mdd/mdd_handler.c index 6e91f90..77763e4 100644 --- a/lustre/mdd/mdd_handler.c +++ b/lustre/mdd/mdd_handler.c @@ -871,6 +871,7 @@ static int mdd_device_init(const struct lu_env *env, struct lu_device *d, mdd->mdd_txn_cb.dtc_txn_stop = mdd_txn_stop_cb; mdd->mdd_txn_cb.dtc_txn_commit = mdd_txn_commit_cb; mdd->mdd_txn_cb.dtc_cookie = mdd; + rc = mdd_procfs_init(mdd); RETURN(rc); } @@ -879,7 +880,13 @@ static struct lu_device *mdd_device_fini(const struct lu_env *env, { struct mdd_device *mdd = lu2mdd_dev(d); struct lu_device *next = &mdd->mdd_child->dd_lu_dev; - + int rc; + + rc = mdd_procfs_fini(mdd); + if (rc) { + CERROR("proc fini error %d \n", rc); + return ERR_PTR(rc); + } return next; } @@ -2621,8 +2628,10 @@ static int mdd_create(const struct lu_env *env, struct lov_mds_md *lmm = NULL; struct thandle *handle; int rc, created = 0, inserted = 0, lmm_size = 0; + struct timeval start; ENTRY; + mdd_lproc_time_start(mdd, &start, LPROC_MDD_CREATE); /* * Two operations have to be performed: * @@ -2783,6 +2792,7 @@ cleanup: OBD_FREE(lmm, lmm_size); mdd_write_unlock(env, mdd_pobj); mdd_trans_stop(env, mdd, rc, handle); + mdd_lproc_time_end(mdd, &start, LPROC_MDD_CREATE); RETURN(rc); } diff --git a/lustre/mdd/mdd_internal.h b/lustre/mdd/mdd_internal.h index 56301c2..559eef0 100644 --- a/lustre/mdd/mdd_internal.h +++ b/lustre/mdd/mdd_internal.h @@ -45,6 +45,8 @@ struct mdd_device { struct dt_device_param mdd_dt_conf; struct dt_object *mdd_orphans; struct dt_txn_callback mdd_txn_cb; + cfs_proc_dir_entry_t *mdd_proc_entry; + struct lprocfs_stats *mdd_stats; }; enum mod_flags { @@ -143,6 +145,11 @@ struct mdd_object *mdd_object_find(const struct lu_env *, const struct lu_fid *); int mdd_txn_init_credits(const struct lu_env *env, struct mdd_device *mdd); +int mdd_procfs_init(struct mdd_device *mdd); +int mdd_procfs_fini(struct mdd_device *mdd); +void mdd_lproc_time_start(struct mdd_device *mdd, struct timeval *start, int op); +void mdd_lproc_time_end(struct mdd_device *mdd, struct timeval *start, int op); + static inline void mdd_object_put(const struct lu_env *env, struct mdd_object *o) { @@ -242,4 +249,9 @@ static inline struct lustre_capa *mdd_object_capa(const struct lu_env *env, return NULL; } +enum { + LPROC_MDD_OPEN = 0, + LPROC_MDD_CREATE, + LPROC_MDD_LAST +}; #endif diff --git a/lustre/mdd/mdd_lproc.c b/lustre/mdd/mdd_lproc.c new file mode 100644 index 0000000..021da3a --- /dev/null +++ b/lustre/mdd/mdd_lproc.c @@ -0,0 +1,138 @@ +/* -*- MODE: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- + * vim:expandtab:shiftwidth=8:tabstop=8: + * + * mdd/mdd_handler.c + * Lustre Metadata Server (mdd) routines + * + * Copyright (C) 2006 Cluster File Systems, Inc. + * Author: Wang Di + * + * This file is part of the Lustre file system, http://www.lustre.org + * Lustre is a trademark of Cluster File Systems, Inc. + * + * You may have signed or agreed to another license before downloading + * this software. If so, you are bound by the terms and conditions + * of that agreement, and the following does not apply to you. See the + * LICENSE file included with this distribution for more information. + * + * If you did not agree to a different license, then this copy of Lustre + * is open source software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * In either case, Lustre is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * license text for more details. + */ +#ifndef EXPORT_SYMTAB +# define EXPORT_SYMTAB +#endif +#define DEBUG_SUBSYSTEM S_MDS + +#include +#include +#include +#include +#include +#include + +#include + +#include "mdd_internal.h" + +static int mdd_procfs_init_stats(struct mdd_device *mdd, int num_stats) +{ + struct lprocfs_stats *stats; + int rc; + ENTRY; + + stats = lprocfs_alloc_stats(num_stats); + if (!stats) + RETURN(-ENOMEM); + + rc = lprocfs_register_stats(mdd->mdd_proc_entry, "stats", stats); + if (rc != 0) + GOTO(cleanup, rc); + + mdd->mdd_stats = stats; + + lprocfs_counter_init(mdd->mdd_stats, LPROC_MDD_OPEN, + LPROCFS_CNTR_AVGMINMAX, "open", "time"); + + lprocfs_counter_init(mdd->mdd_stats, LPROC_MDD_CREATE, + LPROCFS_CNTR_AVGMINMAX, "create", "time"); +cleanup: + if (rc) { + lprocfs_free_stats(stats); + mdd->mdd_stats = NULL; + } + RETURN(rc); +} + +int mdd_procfs_fini(struct mdd_device *mdd) +{ + if (mdd->mdd_stats) { + lprocfs_free_stats(mdd->mdd_stats); + mdd->mdd_stats = NULL; + } + if (mdd->mdd_proc_entry) { + lprocfs_remove(mdd->mdd_proc_entry); + mdd->mdd_proc_entry = NULL; + } + RETURN(0); +} + +int mdd_procfs_init(struct mdd_device *mdd) +{ + struct lu_device *ld = &mdd->mdd_md_dev.md_lu_dev; + struct obd_type *type; + char mdd_name[10]; + int rc = 0; + ENTRY; + + type = ld->ld_type->ldt_obd_type; + + LASSERT(type != NULL); + + memset(mdd_name, 0, sizeof(mdd_name)); + snprintf(mdd_name, strlen(LUSTRE_MDD_NAME) + 5, "%s-%d", + LUSTRE_MDD_NAME, (int)ld->ld_site->ls_node_id); + + /* find the type procroot and add the proc entry for this device */ + mdd->mdd_proc_entry = lprocfs_register(mdd_name, type->typ_procroot, + NULL, NULL); + if (IS_ERR(mdd->mdd_proc_entry)) { + rc = PTR_ERR(mdd->mdd_proc_entry); + CERROR("error %d setting up lprocfs for %s\n", + rc, mdd_name); + mdd->mdd_proc_entry = NULL; + GOTO(out, rc); + } + + rc = mdd_procfs_init_stats(mdd, LPROC_MDD_LAST); +out: + if (rc) + mdd_procfs_fini(mdd); + RETURN(rc); +} + +void mdd_lproc_time_start(struct mdd_device *mdd, struct timeval *start, int op) +{ + do_gettimeofday(start); +} + +void mdd_lproc_time_end(struct mdd_device *mdd, struct timeval *start, int op) +{ + struct timeval end; + long timediff; + + do_gettimeofday(&end); + timediff = cfs_timeval_sub(&end, start, NULL); + + if (mdd->mdd_stats) + lprocfs_counter_add(mdd->mdd_stats, op, timediff); + return; +} + + -- 1.8.3.1