1321936Shselasky/*
2321936Shselasky * Copyright (c) 2004-2009 Voltaire, Inc. All rights reserved.
3321936Shselasky * Copyright (c) 2002-2012 Mellanox Technologies LTD. All rights reserved.
4321936Shselasky * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5321936Shselasky *
6321936Shselasky * This software is available to you under a choice of one of two
7321936Shselasky * licenses.  You may choose to be licensed under the terms of the GNU
8321936Shselasky * General Public License (GPL) Version 2, available from the file
9321936Shselasky * COPYING in the main directory of this source tree, or the
10321936Shselasky * OpenIB.org BSD license below:
11321936Shselasky *
12321936Shselasky *     Redistribution and use in source and binary forms, with or
13321936Shselasky *     without modification, are permitted provided that the following
14321936Shselasky *     conditions are met:
15321936Shselasky *
16321936Shselasky *      - Redistributions of source code must retain the above
17321936Shselasky *        copyright notice, this list of conditions and the following
18321936Shselasky *        disclaimer.
19321936Shselasky *
20321936Shselasky *      - Redistributions in binary form must reproduce the above
21321936Shselasky *        copyright notice, this list of conditions and the following
22321936Shselasky *        disclaimer in the documentation and/or other materials
23321936Shselasky *        provided with the distribution.
24321936Shselasky *
25321936Shselasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26321936Shselasky * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27321936Shselasky * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28321936Shselasky * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29321936Shselasky * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30321936Shselasky * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31321936Shselasky * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32321936Shselasky * SOFTWARE.
33321936Shselasky *
34321936Shselasky */
35321936Shselasky
36321936Shselasky/*
37321936Shselasky * Abstract:
38321936Shselasky * 	Declaration of osm_log_t.
39321936Shselasky *	This object represents the log file.
40321936Shselasky *	This object is part of the OpenSM family of objects.
41321936Shselasky */
42321936Shselasky
43321936Shselasky#ifndef _OSM_LOG_H_
44321936Shselasky#define _OSM_LOG_H_
45321936Shselasky
46321936Shselasky#ifndef __WIN__
47321936Shselasky#include <syslog.h>
48321936Shselasky#endif
49321936Shselasky#include <complib/cl_spinlock.h>
50321936Shselasky#include <opensm/osm_base.h>
51321936Shselasky#include <iba/ib_types.h>
52321936Shselasky#include <stdio.h>
53321936Shselasky
54321936Shselasky#ifdef __GNUC__
55321936Shselasky#define STRICT_OSM_LOG_FORMAT __attribute__((format(printf, 3, 4)))
56321936Shselasky#define STRICT_OSM_LOG_V2_FORMAT __attribute__((format(printf, 4, 5)))
57321936Shselasky#else
58321936Shselasky#define STRICT_OSM_LOG_FORMAT
59321936Shselasky#define STRICT_OSM_LOG_V2_FORMAT
60321936Shselasky#endif
61321936Shselasky
62321936Shselasky#ifdef __cplusplus
63321936Shselasky#  define BEGIN_C_DECLS extern "C" {
64321936Shselasky#  define END_C_DECLS   }
65321936Shselasky#else				/* !__cplusplus */
66321936Shselasky#  define BEGIN_C_DECLS
67321936Shselasky#  define END_C_DECLS
68321936Shselasky#endif				/* __cplusplus */
69321936Shselasky
70321936ShselaskyBEGIN_C_DECLS
71321936Shselasky#define LOG_ENTRY_SIZE_MAX		4096
72321936Shselasky#define BUF_SIZE			LOG_ENTRY_SIZE_MAX
73321936Shselasky#define __func__ __FUNCTION__
74321936Shselasky#ifdef FILE_ID
75321936Shselasky#define OSM_LOG_ENTER( OSM_LOG_PTR ) \
76321936Shselasky	osm_log_v2( OSM_LOG_PTR, OSM_LOG_FUNCS, FILE_ID, \
77321936Shselasky		    "%s: [\n", __func__);
78321936Shselasky#define OSM_LOG_EXIT( OSM_LOG_PTR ) \
79321936Shselasky	osm_log_v2( OSM_LOG_PTR, OSM_LOG_FUNCS, FILE_ID, \
80321936Shselasky		    "%s: ]\n", __func__);
81321936Shselasky#define OSM_LOG_IS_ACTIVE_V2( OSM_LOG_PTR, OSM_LOG_FUNCS ) \
82321936Shselasky	osm_log_is_active_v2( OSM_LOG_PTR, OSM_LOG_FUNCS, FILE_ID)
83321936Shselasky#else
84321936Shselasky#define OSM_LOG_ENTER( OSM_LOG_PTR ) \
85321936Shselasky	osm_log( OSM_LOG_PTR, OSM_LOG_FUNCS, \
86321936Shselasky		 "%s: [\n", __func__);
87321936Shselasky#define OSM_LOG_EXIT( OSM_LOG_PTR ) \
88321936Shselasky	osm_log( OSM_LOG_PTR, OSM_LOG_FUNCS, \
89321936Shselasky		 "%s: ]\n", __func__);
90321936Shselasky#endif
91321936Shselasky
92321936Shselasky/****h* OpenSM/Log
93321936Shselasky* NAME
94321936Shselasky*	Log
95321936Shselasky*
96321936Shselasky* DESCRIPTION
97321936Shselasky*
98321936Shselasky* AUTHOR
99321936Shselasky*
100321936Shselasky*********/
101321936Shselaskytypedef uint8_t osm_log_level_t;
102321936Shselasky
103321936Shselasky#define OSM_LOG_NONE	0x00
104321936Shselasky#define OSM_LOG_ERROR	0x01
105321936Shselasky#define OSM_LOG_INFO	0x02
106321936Shselasky#define OSM_LOG_VERBOSE	0x04
107321936Shselasky#define OSM_LOG_DEBUG	0x08
108321936Shselasky#define OSM_LOG_FUNCS	0x10
109321936Shselasky#define OSM_LOG_FRAMES	0x20
110321936Shselasky#define OSM_LOG_ROUTING	0x40
111321936Shselasky#define OSM_LOG_ALL	0x7f
112321936Shselasky#define OSM_LOG_SYS	0x80
113321936Shselasky
114321936Shselasky/*
115321936Shselasky	DEFAULT - turn on ERROR and INFO only
116321936Shselasky*/
117321936Shselasky#define OSM_LOG_DEFAULT_LEVEL		OSM_LOG_ERROR | OSM_LOG_INFO
118321936Shselasky
119321936Shselasky/****s* OpenSM: Log/osm_log_t
120321936Shselasky* NAME
121321936Shselasky*	osm_log_t
122321936Shselasky*
123321936Shselasky* DESCRIPTION
124321936Shselasky*
125321936Shselasky* SYNOPSIS
126321936Shselasky*/
127321936Shselaskytypedef struct osm_log {
128321936Shselasky	osm_log_level_t level;
129321936Shselasky	cl_spinlock_t lock;
130321936Shselasky	unsigned long count;
131321936Shselasky	unsigned long max_size;
132321936Shselasky	boolean_t flush;
133321936Shselasky	FILE *out_port;
134321936Shselasky	boolean_t accum_log_file;
135321936Shselasky	boolean_t daemon;
136321936Shselasky	char *log_file_name;
137321936Shselasky	char *log_prefix;
138321936Shselasky	osm_log_level_t per_mod_log_tbl[256];
139321936Shselasky} osm_log_t;
140321936Shselasky/*********/
141321936Shselasky
142321936Shselasky#define OSM_LOG_MOD_NAME_MAX	32
143321936Shselasky
144321936Shselasky/****f* OpenSM: Log/osm_get_log_per_module
145321936Shselasky * NAME
146321936Shselasky *	osm_get_log_per_module
147321936Shselasky *
148321936Shselasky * DESCRIPTION
149321936Shselasky *	This looks up the given file ID in the per module log table.
150321936Shselasky *	NOTE: this code is not thread safe. Need to grab the lock before
151321936Shselasky *	calling it.
152321936Shselasky *
153321936Shselasky * SYNOPSIS
154321936Shselasky */
155321936Shselaskyosm_log_level_t osm_get_log_per_module(IN osm_log_t * p_log,
156321936Shselasky				       IN const int file_id);
157321936Shselasky/*
158321936Shselasky * PARAMETERS
159321936Shselasky *	p_log
160321936Shselasky *		[in] Pointer to a Log object to construct.
161321936Shselasky *
162321936Shselasky *	file_id
163321936Shselasky *		[in] File ID for module
164321936Shselasky *
165321936Shselasky * RETURN VALUES
166321936Shselasky *	The log level from the per module logging structure for this file ID.
167321936Shselasky *********/
168321936Shselasky
169321936Shselasky/****f* OpenSM: Log/osm_set_log_per_module
170321936Shselasky * NAME
171321936Shselasky *	osm_set_log_per_module
172321936Shselasky *
173321936Shselasky * DESCRIPTION
174321936Shselasky *	This sets log level for the given file ID in the per module log table.
175321936Shselasky *	NOTE: this code is not thread safe. Need to grab the lock before
176321936Shselasky *	calling it.
177321936Shselasky *
178321936Shselasky * SYNOPSIS
179321936Shselasky */
180321936Shselaskyvoid osm_set_log_per_module(IN osm_log_t * p_log, IN const int file_id,
181321936Shselasky			    IN osm_log_level_t level);
182321936Shselasky/*
183321936Shselasky * PARAMETERS
184321936Shselasky *	p_log
185321936Shselasky *		[in] Pointer to a Log object to construct.
186321936Shselasky *
187321936Shselasky *	file_id
188321936Shselasky *		[in] File ID for module
189321936Shselasky *
190321936Shselasky *	level
191321936Shselasky *		[in] Log level of the module
192321936Shselasky *
193321936Shselasky * RETURN VALUES
194321936Shselasky *	This function does not return a value.
195321936Shselasky *********/
196321936Shselasky
197321936Shselasky/****f* OpenSM: Log/osm_reset_log_per_module
198321936Shselasky * NAME
199321936Shselasky *	osm_reset_log_per_module
200321936Shselasky *
201321936Shselasky * DESCRIPTION
202321936Shselasky *	This resets log level for the entire per module log table.
203321936Shselasky *	NOTE: this code is not thread safe. Need to grab the lock before
204321936Shselasky *	calling it.
205321936Shselasky *
206321936Shselasky * SYNOPSIS
207321936Shselasky */
208321936Shselaskyvoid osm_reset_log_per_module(IN osm_log_t * p_log);
209321936Shselasky/*
210321936Shselasky * PARAMETERS
211321936Shselasky *	p_log
212321936Shselasky *		[in] Pointer to a Log object to construct.
213321936Shselasky *
214321936Shselasky * RETURN VALUES
215321936Shselasky *	This function does not return a value.
216321936Shselasky *********/
217321936Shselasky
218321936Shselasky/****f* OpenSM: Log/osm_log_construct
219321936Shselasky* NAME
220321936Shselasky*	osm_log_construct
221321936Shselasky*
222321936Shselasky* DESCRIPTION
223321936Shselasky*	This function constructs a Log object.
224321936Shselasky*
225321936Shselasky* SYNOPSIS
226321936Shselasky*/
227321936Shselaskystatic inline void osm_log_construct(IN osm_log_t * p_log)
228321936Shselasky{
229321936Shselasky	cl_spinlock_construct(&p_log->lock);
230321936Shselasky}
231321936Shselasky
232321936Shselasky/*
233321936Shselasky* PARAMETERS
234321936Shselasky*	p_log
235321936Shselasky*		[in] Pointer to a Log object to construct.
236321936Shselasky*
237321936Shselasky* RETURN VALUE
238321936Shselasky*	This function does not return a value.
239321936Shselasky*
240321936Shselasky* NOTES
241321936Shselasky*	Allows calling osm_log_init, osm_log_init_v2, osm_log_destroy
242321936Shselasky*
243321936Shselasky*	Calling osm_log_construct is a prerequisite to calling any other
244321936Shselasky*	method except osm_log_init or osm_log_init_v2.
245321936Shselasky*
246321936Shselasky* SEE ALSO
247321936Shselasky*	Log object, osm_log_init, osm_log_init_v2,
248321936Shselasky*	osm_log_destroy
249321936Shselasky*********/
250321936Shselasky
251321936Shselasky/****f* OpenSM: Log/osm_log_destroy
252321936Shselasky* NAME
253321936Shselasky*	osm_log_destroy
254321936Shselasky*
255321936Shselasky* DESCRIPTION
256321936Shselasky*	The osm_log_destroy function destroys the object, releasing
257321936Shselasky*	all resources.
258321936Shselasky*
259321936Shselasky* SYNOPSIS
260321936Shselasky*/
261321936Shselaskystatic inline void osm_log_destroy(IN osm_log_t * p_log)
262321936Shselasky{
263321936Shselasky	cl_spinlock_destroy(&p_log->lock);
264321936Shselasky	if (p_log->out_port != stdout) {
265321936Shselasky		fclose(p_log->out_port);
266321936Shselasky		p_log->out_port = stdout;
267321936Shselasky	}
268321936Shselasky	closelog();
269321936Shselasky}
270321936Shselasky
271321936Shselasky/*
272321936Shselasky* PARAMETERS
273321936Shselasky*	p_log
274321936Shselasky*		[in] Pointer to the object to destroy.
275321936Shselasky*
276321936Shselasky* RETURN VALUE
277321936Shselasky*	This function does not return a value.
278321936Shselasky*
279321936Shselasky* NOTES
280321936Shselasky*	Performs any necessary cleanup of the specified
281321936Shselasky*	Log object.
282321936Shselasky*	Further operations should not be attempted on the destroyed object.
283321936Shselasky*	This function should only be called after a call to
284321936Shselasky*	osm_log_construct, osm_log_init, or osm_log_init_v2.
285321936Shselasky*
286321936Shselasky* SEE ALSO
287321936Shselasky*	Log object, osm_log_construct,
288321936Shselasky*	osm_log_init, osm_log_init_v2
289321936Shselasky*********/
290321936Shselasky
291321936Shselasky/****f* OpenSM: Log/osm_log_init_v2
292321936Shselasky* NAME
293321936Shselasky*	osm_log_init_v2
294321936Shselasky*
295321936Shselasky* DESCRIPTION
296321936Shselasky*	The osm_log_init_v2 function initializes a
297321936Shselasky*	Log object for use.
298321936Shselasky*
299321936Shselasky* SYNOPSIS
300321936Shselasky*/
301321936Shselaskyib_api_status_t osm_log_init_v2(IN osm_log_t * p_log, IN boolean_t flush,
302321936Shselasky				IN uint8_t log_flags, IN const char *log_file,
303321936Shselasky				IN unsigned long max_size,
304321936Shselasky				IN boolean_t accum_log_file);
305321936Shselasky/*
306321936Shselasky* PARAMETERS
307321936Shselasky*	p_log
308321936Shselasky*		[in] Pointer to the log object.
309321936Shselasky*
310321936Shselasky*	flush
311321936Shselasky*		[in] Set to TRUE directs the log to flush all log messages
312321936Shselasky*		immediately.  This severely degrades log performance,
313321936Shselasky*		and is normally used for debugging only.
314321936Shselasky*
315321936Shselasky*	log_flags
316321936Shselasky*		[in] The log verbosity level to be used.
317321936Shselasky*
318321936Shselasky*	log_file
319321936Shselasky*		[in] if not NULL defines the name of the log file. Otherwise
320321936Shselasky*		it is stdout.
321321936Shselasky*
322321936Shselasky* RETURN VALUES
323321936Shselasky*	CL_SUCCESS if the Log object was initialized
324321936Shselasky*	successfully.
325321936Shselasky*
326321936Shselasky* NOTES
327321936Shselasky*	Allows calling other Log methods.
328321936Shselasky*
329321936Shselasky* SEE ALSO
330321936Shselasky*	Log object, osm_log_construct,
331321936Shselasky*	osm_log_destroy
332321936Shselasky*********/
333321936Shselasky
334321936Shselasky/****f* OpenSM: Log/osm_log_reopen_file
335321936Shselasky* NAME
336321936Shselasky*	osm_log_reopen_file
337321936Shselasky*
338321936Shselasky* DESCRIPTION
339321936Shselasky*	The osm_log_reopen_file function reopens the log file
340321936Shselasky*
341321936Shselasky* SYNOPSIS
342321936Shselasky*/
343321936Shselaskyint osm_log_reopen_file(osm_log_t * p_log);
344321936Shselasky/*
345321936Shselasky* PARAMETERS
346321936Shselasky*	p_log
347321936Shselasky*		[in] Pointer to the log object.
348321936Shselasky*
349321936Shselasky* RETURN VALUES
350321936Shselasky*	0 on success or nonzero value otherwise.
351321936Shselasky*********/
352321936Shselasky
353321936Shselasky/****f* OpenSM: Log/osm_log_init
354321936Shselasky* NAME
355321936Shselasky*	osm_log_init
356321936Shselasky*
357321936Shselasky* DESCRIPTION
358321936Shselasky*	The osm_log_init function initializes a
359321936Shselasky*	Log object for use. It is a wrapper for osm_log_init_v2().
360321936Shselasky*
361321936Shselasky* SYNOPSIS
362321936Shselasky*/
363321936Shselaskyib_api_status_t osm_log_init(IN osm_log_t * p_log, IN boolean_t flush,
364321936Shselasky			     IN uint8_t log_flags, IN const char *log_file,
365321936Shselasky			     IN boolean_t accum_log_file);
366321936Shselasky/*
367321936Shselasky * Same as osm_log_init_v2() but without max_size parameter
368321936Shselasky */
369321936Shselasky
370321936Shselaskyvoid osm_log(IN osm_log_t * p_log, IN osm_log_level_t verbosity,
371321936Shselasky	     IN const char *p_str, ...) STRICT_OSM_LOG_FORMAT;
372321936Shselasky
373321936Shselaskyvoid osm_log_v2(IN osm_log_t * p_log, IN osm_log_level_t verbosity,
374321936Shselasky		IN const int file_id, IN const char *p_str, ...) STRICT_OSM_LOG_V2_FORMAT;
375321936Shselasky
376321936Shselasky/****f* OpenSM: Log/osm_log_get_level
377321936Shselasky* NAME
378321936Shselasky*	osm_log_get_level
379321936Shselasky*
380321936Shselasky* DESCRIPTION
381321936Shselasky*	Returns the current log level.
382321936Shselasky*
383321936Shselasky* SYNOPSIS
384321936Shselasky*/
385321936Shselaskystatic inline osm_log_level_t osm_log_get_level(IN const osm_log_t * p_log)
386321936Shselasky{
387321936Shselasky	return p_log->level;
388321936Shselasky}
389321936Shselasky
390321936Shselasky/*
391321936Shselasky* PARAMETERS
392321936Shselasky*	p_log
393321936Shselasky*		[in] Pointer to the log object.
394321936Shselasky*
395321936Shselasky* RETURN VALUES
396321936Shselasky*	Returns the current log level.
397321936Shselasky*
398321936Shselasky* NOTES
399321936Shselasky*
400321936Shselasky* SEE ALSO
401321936Shselasky*	Log object, osm_log_construct,
402321936Shselasky*	osm_log_destroy
403321936Shselasky*********/
404321936Shselasky
405321936Shselasky/****f* OpenSM: Log/osm_log_set_level
406321936Shselasky* NAME
407321936Shselasky*	osm_log_set_level
408321936Shselasky*
409321936Shselasky* DESCRIPTION
410321936Shselasky*	Sets the current log level.
411321936Shselasky*
412321936Shselasky* SYNOPSIS
413321936Shselasky*/
414321936Shselaskystatic inline void osm_log_set_level(IN osm_log_t * p_log,
415321936Shselasky				     IN osm_log_level_t level)
416321936Shselasky{
417321936Shselasky	p_log->level = level;
418321936Shselasky	osm_log(p_log, OSM_LOG_ALL, "Setting log level to: 0x%02x\n", level);
419321936Shselasky}
420321936Shselasky
421321936Shselasky/*
422321936Shselasky* PARAMETERS
423321936Shselasky*	p_log
424321936Shselasky*		[in] Pointer to the log object.
425321936Shselasky*
426321936Shselasky*	level
427321936Shselasky*		[in] New level to set.
428321936Shselasky*
429321936Shselasky* RETURN VALUES
430321936Shselasky*	This function does not return a value.
431321936Shselasky*
432321936Shselasky* NOTES
433321936Shselasky*
434321936Shselasky* SEE ALSO
435321936Shselasky*	Log object, osm_log_construct,
436321936Shselasky*	osm_log_destroy
437321936Shselasky*********/
438321936Shselasky
439321936Shselasky/****f* OpenSM: Log/osm_log_is_active
440321936Shselasky* NAME
441321936Shselasky*	osm_log_is_active
442321936Shselasky*
443321936Shselasky* DESCRIPTION
444321936Shselasky*	Returns TRUE if the specified log level would be logged.
445321936Shselasky*	FALSE otherwise.
446321936Shselasky*
447321936Shselasky* SYNOPSIS
448321936Shselasky*/
449321936Shselaskystatic inline boolean_t osm_log_is_active(IN const osm_log_t * p_log,
450321936Shselasky					  IN osm_log_level_t level)
451321936Shselasky{
452321936Shselasky	return ((p_log->level & level) != 0);
453321936Shselasky}
454321936Shselasky
455321936Shselasky/*
456321936Shselasky* PARAMETERS
457321936Shselasky*	p_log
458321936Shselasky*		[in] Pointer to the log object.
459321936Shselasky*
460321936Shselasky*	level
461321936Shselasky*		[in] Level to check.
462321936Shselasky*
463321936Shselasky* RETURN VALUES
464321936Shselasky*	Returns TRUE if the specified log level would be logged.
465321936Shselasky*	FALSE otherwise.
466321936Shselasky*
467321936Shselasky* NOTES
468321936Shselasky*
469321936Shselasky* SEE ALSO
470321936Shselasky*	Log object, osm_log_construct,
471321936Shselasky*	osm_log_destroy
472321936Shselasky*********/
473321936Shselasky
474321936Shselaskystatic inline boolean_t osm_log_is_active_v2(IN const osm_log_t * p_log,
475321936Shselasky					     IN osm_log_level_t level,
476321936Shselasky					     IN const int file_id)
477321936Shselasky{
478321936Shselasky	if ((p_log->level & level) != 0)
479321936Shselasky		return 1;
480321936Shselasky	if ((level & p_log->per_mod_log_tbl[file_id]))
481321936Shselasky		return 1;
482321936Shselasky	return 0;
483321936Shselasky}
484321936Shselasky
485321936Shselaskyextern void osm_log_msg_box(osm_log_t *log, osm_log_level_t level,
486321936Shselasky			    const char *func_name, const char *msg);
487321936Shselaskyextern void osm_log_msg_box_v2(osm_log_t *log, osm_log_level_t level,
488321936Shselasky			       const int file_id, const char *func_name,
489321936Shselasky			       const char *msg);
490321936Shselaskyextern void osm_log_raw(IN osm_log_t * p_log, IN osm_log_level_t verbosity,
491321936Shselasky			IN const char *p_buf);
492321936Shselasky
493321936Shselasky#ifdef FILE_ID
494321936Shselasky#define OSM_LOG(log, level, fmt, ...) do { \
495321936Shselasky		if (osm_log_is_active_v2(log, (level), FILE_ID)) \
496321936Shselasky			osm_log_v2(log, level, FILE_ID, "%s: " fmt, __func__, ## __VA_ARGS__); \
497321936Shselasky	} while (0)
498321936Shselasky
499321936Shselasky#define OSM_LOG_MSG_BOX(log, level, msg) \
500321936Shselasky		osm_log_msg_box_v2(log, level, FILE_ID, __func__, msg)
501321936Shselasky#else
502321936Shselasky#define OSM_LOG(log, level, fmt, ...) do { \
503321936Shselasky		if (osm_log_is_active(log, (level))) \
504321936Shselasky			osm_log(log, level, "%s: " fmt, __func__, ## __VA_ARGS__); \
505321936Shselasky	} while (0)
506321936Shselasky
507321936Shselasky#define OSM_LOG_MSG_BOX(log, level, msg) \
508321936Shselasky		osm_log_msg_box(log, level, __func__, msg)
509321936Shselasky#endif
510321936Shselasky
511321936Shselasky#define DBG_CL_LOCK 0
512321936Shselasky
513321936Shselasky#define CL_PLOCK_EXCL_ACQUIRE( __exp__ )  \
514321936Shselasky{											    		\
515321936Shselasky   if (DBG_CL_LOCK)                      \
516321936Shselasky     printf("cl_plock_excl_acquire: Acquiring %p file %s, line %d\n", \
517321936Shselasky          __exp__,__FILE__, __LINE__);            \
518321936Shselasky   cl_plock_excl_acquire( __exp__ );      \
519321936Shselasky   if (DBG_CL_LOCK)                      \
520321936Shselasky     printf("cl_plock_excl_acquire: Acquired %p file %s, line %d\n", \
521321936Shselasky          __exp__,__FILE__, __LINE__);            \
522321936Shselasky}
523321936Shselasky
524321936Shselasky#define CL_PLOCK_ACQUIRE( __exp__ )  \
525321936Shselasky{											    		\
526321936Shselasky   if (DBG_CL_LOCK)                      \
527321936Shselasky     printf("cl_plock_acquire: Acquiring %p file %s, line %d\n", \
528321936Shselasky          __exp__,__FILE__, __LINE__);            \
529321936Shselasky   cl_plock_acquire( __exp__ );      \
530321936Shselasky   if (DBG_CL_LOCK)                      \
531321936Shselasky     printf("cl_plock_acquire: Acquired %p file %s, line %d\n", \
532321936Shselasky          __exp__,__FILE__, __LINE__);            \
533321936Shselasky}
534321936Shselasky
535321936Shselasky#define CL_PLOCK_RELEASE( __exp__ )  \
536321936Shselasky{											    		\
537321936Shselasky   if (DBG_CL_LOCK)                      \
538321936Shselasky     printf("cl_plock_release: Releasing %p file %s, line %d\n", \
539321936Shselasky          __exp__,__FILE__, __LINE__);            \
540321936Shselasky   cl_plock_release( __exp__ );      \
541321936Shselasky   if (DBG_CL_LOCK)                      \
542321936Shselasky     printf("cl_plock_release: Released  %p file %s, line %d\n", \
543321936Shselasky          __exp__,__FILE__, __LINE__);            \
544321936Shselasky}
545321936Shselasky
546321936Shselasky#define DBG_CL_SPINLOCK 0
547321936Shselasky#define CL_SPINLOCK_RELEASE( __exp__ )  \
548321936Shselasky{											    		\
549321936Shselasky   if (DBG_CL_SPINLOCK)                      \
550321936Shselasky     printf("cl_spinlock_release: Releasing %p file %s, line %d\n", \
551321936Shselasky          __exp__,__FILE__, __LINE__);            \
552321936Shselasky   cl_spinlock_release( __exp__ );      \
553321936Shselasky   if (DBG_CL_SPINLOCK)                      \
554321936Shselasky     printf("cl_spinlock_release: Released  %p file %s, line %d\n", \
555321936Shselasky          __exp__,__FILE__, __LINE__);            \
556321936Shselasky}
557321936Shselasky
558321936Shselasky#define CL_SPINLOCK_ACQUIRE( __exp__ )  \
559321936Shselasky{											    		\
560321936Shselasky   if (DBG_CL_SPINLOCK)                      \
561321936Shselasky     printf("cl_spinlock_acquire: Acquiring %p file %s, line %d\n", \
562321936Shselasky          __exp__,__FILE__, __LINE__);            \
563321936Shselasky   cl_spinlock_acquire( __exp__ );      \
564321936Shselasky   if (DBG_CL_SPINLOCK)                      \
565321936Shselasky     printf("cl_spinlock_acquire: Acquired %p file %s, line %d\n", \
566321936Shselasky          __exp__,__FILE__, __LINE__);            \
567321936Shselasky}
568321936Shselasky
569321936Shselasky/****f* OpenSM: Helper/osm_is_debug
570321936Shselasky* NAME
571321936Shselasky*	osm_is_debug
572321936Shselasky*
573321936Shselasky* DESCRIPTION
574321936Shselasky*	The osm_is_debug function returns TRUE if the opensm was compiled
575321936Shselasky*	in debug mode, and FALSE otherwise.
576321936Shselasky*
577321936Shselasky* SYNOPSIS
578321936Shselasky*/
579321936Shselaskyboolean_t osm_is_debug(void);
580321936Shselasky/*
581321936Shselasky* PARAMETERS
582321936Shselasky*	None
583321936Shselasky*
584321936Shselasky* RETURN VALUE
585321936Shselasky*	TRUE if compiled in debug version. FALSE otherwise.
586321936Shselasky*
587321936Shselasky* NOTES
588321936Shselasky*
589321936Shselasky*********/
590321936Shselasky
591321936ShselaskyEND_C_DECLS
592321936Shselasky#endif				/* _OSM_LOG_H_ */
593