Deleted Added
full compact
subr_lock.c (164889) subr_lock.c (167012)
1/*-
2 * Copyright (c) 2006 John Baldwin <jhb@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 19 unchanged lines hidden (view full) ---

28 */
29
30/*
31 * This module holds the global variables and functions used to maintain
32 * lock_object structures.
33 */
34
35#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2006 John Baldwin <jhb@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 19 unchanged lines hidden (view full) ---

28 */
29
30/*
31 * This module holds the global variables and functions used to maintain
32 * lock_object structures.
33 */
34
35#include <sys/cdefs.h>
36__FBSDID("$FreeBSD: head/sys/kern/subr_lock.c 164889 2006-12-04 22:15:50Z kmacy $");
36__FBSDID("$FreeBSD: head/sys/kern/subr_lock.c 167012 2007-02-26 08:26:44Z kmacy $");
37
38#include "opt_ddb.h"
39#include "opt_mprof.h"
40
41#include <sys/param.h>
42#include <sys/systm.h>
43#include <sys/ktr.h>
44#include <sys/linker_set.h>

--- 200 unchanged lines hidden (view full) ---

245 db_printf(" name: %s\n", lock->lo_name);
246 if (lock->lo_type && lock->lo_type != lock->lo_name)
247 db_printf(" type: %s\n", lock->lo_type);
248 class->lc_ddb_show(lock);
249}
250#endif
251
252#ifdef LOCK_PROFILING
37
38#include "opt_ddb.h"
39#include "opt_mprof.h"
40
41#include <sys/param.h>
42#include <sys/systm.h>
43#include <sys/ktr.h>
44#include <sys/linker_set.h>

--- 200 unchanged lines hidden (view full) ---

245 db_printf(" name: %s\n", lock->lo_name);
246 if (lock->lo_type && lock->lo_type != lock->lo_name)
247 db_printf(" type: %s\n", lock->lo_type);
248 class->lc_ddb_show(lock);
249}
250#endif
251
252#ifdef LOCK_PROFILING
253void _lock_profile_obtain_lock_success(struct lock_object *lo, uint64_t waittime, con\
254st char *file, int line)
253void _lock_profile_obtain_lock_success(struct lock_object *lo, int contested, uint64_t waittime, const char *file, int line)
255{
256 struct lock_profile_object *l = &lo->lo_profile_obj;
257
258 /* don't reset the timer when/if recursing */
259 if (l->lpo_acqtime == 0) {
254{
255 struct lock_profile_object *l = &lo->lo_profile_obj;
256
257 /* don't reset the timer when/if recursing */
258 if (l->lpo_acqtime == 0) {
259 lo->lo_profile_obj.lpo_contest_holding = 0;
260
261 if (contested)
262 lo->lo_profile_obj.lpo_contest_locking++;
263
260 l->lpo_filename = file;
261 l->lpo_lineno = line;
262 l->lpo_acqtime = nanoseconds();
263 if (waittime && (l->lpo_acqtime > waittime))
264 l->lpo_waittime = l->lpo_acqtime - waittime;
265 else
266 l->lpo_waittime = 0;
267 }
268}
269
264 l->lpo_filename = file;
265 l->lpo_lineno = line;
266 l->lpo_acqtime = nanoseconds();
267 if (waittime && (l->lpo_acqtime > waittime))
268 l->lpo_waittime = l->lpo_acqtime - waittime;
269 else
270 l->lpo_waittime = 0;
271 }
272}
273
270void _lock_profile_update_wait(struct lock_object *lo, uint64_t waitstart)
271{
272 struct lock_profile_object *l = &lo->lo_profile_obj;
273
274 if (lock_prof_enable && waitstart) {
275 uint64_t now, waittime;
276 struct lock_prof *mpp;
277 u_int hash;
278 const char *p = l->lpo_filename;
279 int collision = 0;
280 now = nanoseconds();
281 if (now < waitstart)
282 return;
283 waittime = now - waitstart;
284 hash = (l->lpo_namehash * 31 * 31 + (uintptr_t)p * 31 + l->lpo_lineno) & LPROF_HASH_MASK;
285
286 mpp = &lprof_buf[hash];
287 while (mpp->name != NULL) {
288 if (mpp->line == l->lpo_lineno &&
289 mpp->file == p &&
290 mpp->namehash == l->lpo_namehash)
291 break;
292 /* If the lprof_hash entry is allocated to someone else, try the next one */
293 collision = 1;
294 CTR4(KTR_SPARE1, "Hash collision, %s:%d %s(%x)", mpp->file, mpp->line, mpp->name, mpp->namehash);
295 hash = (hash + 1) & LPROF_HASH_MASK;
296 mpp = &lprof_buf[hash];
297 }
298 if (mpp->name == NULL) {
299 int buf;
300
301 buf = atomic_fetchadd_int(&allocated_lprof_buf, 1);
302 /* Just exit if we cannot get a trace buffer */
303 if (buf >= LPROF_HASH_SIZE) {
304 ++lock_prof_rejected;
305 return;
306 }
307 mpp->file = p;
308 mpp->line = l->lpo_lineno;
309 mpp->namehash = l->lpo_namehash;
310 mpp->type = l->lpo_type;
311 mpp->name = lo->lo_name;
312 if (collision)
313 ++lock_prof_collisions;
314 /* We might have raced someone else but who cares, they'll try again next time */
315 ++lock_prof_records;
316 }
317 LPROF_LOCK(hash);
318 mpp->cnt_wait += waittime;
319 LPROF_UNLOCK(hash);
320 }
321}
322
323void _lock_profile_release_lock(struct lock_object *lo)
324{
325 struct lock_profile_object *l = &lo->lo_profile_obj;
326
327 if (l->lpo_acqtime && !(lo->lo_flags & LO_NOPROFILE)) {
328 const char *unknown = "(unknown)";
329 u_int64_t acqtime, now, waittime;
330 struct lock_prof *mpp;

--- 80 unchanged lines hidden ---
274void _lock_profile_release_lock(struct lock_object *lo)
275{
276 struct lock_profile_object *l = &lo->lo_profile_obj;
277
278 if (l->lpo_acqtime && !(lo->lo_flags & LO_NOPROFILE)) {
279 const char *unknown = "(unknown)";
280 u_int64_t acqtime, now, waittime;
281 struct lock_prof *mpp;

--- 80 unchanged lines hidden ---