This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Locking of global variables
- From: Mike Mason <mmlnx at us dot ibm dot com>
- To: systemTAP <systemtap at sources dot redhat dot com>
- Date: Fri, 10 Aug 2007 15:13:23 -0700
- Subject: Locking of global variables
If I access (read or write) a global variable in a probe handler, how long is it locked? From looking at the generated code, I think it's locked until the handler returns. Does this mean we should avoid the use of globals whenever possible?
I'm asking because I'm considering doing something like the following to minimize code duplication in a set of probes handlers. One good thing is the unused globals still get elided, so this method doesn't do unnecessary work. The bad thing, I think, is that the additional locking may affect the performance of the probed function and increase the potential for skipped probes. Am I missing something?
global maxbytes
global dev
global devname
global devmajor
global devminor
global inode
global filename
global pathname
global fstype
global ftype
function get_file_data (file) {
maxbytes = _file_maxbytes(file)
dev = _file_dev(file)
devname = _bdevname(_file_bdev(file))
devmajor = _dev_major(dev)
devminor = _dev_minor(dev)
inode = _file_ino(file)
filename = _file_filename(file)
pathname = _file_pathname(file)
fstype = _file_fstype(file)
ftype = _file_type(file)
}
global reads, writes
probe kernel.function("vfs_read") {
get_file_data($file)
reads[pathname, fstype]++
}
probe kernel.function("vfs_read") {
get_file_data($file)
writes[pathname, fstype]++
}
Mike