You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
software/kkk/los_lockdep.h

174 lines
6.1 KiB

12 months ago
/* ----------------------------------------------------------------------------
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* Description: Lock Dependency Check.
* Author: Huawei LiteOS Team
* Create: 2018-10-18
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
/**
* @defgroup los_lockdep lockdep
* @ingroup kernel
*/
#ifndef _LOS_LOCKDEP_H
#define _LOS_LOCKDEP_H
#include "los_config.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
typedef struct Spinlock SPIN_LOCK_S;
#ifdef LOSCFG_KERNEL_SMP_LOCKDEP
#define MAX_LOCK_DEPTH 16U
enum LockDepErrType {
LOCKDEP_SUCEESS = 0,
LOCKDEP_ERR_DOUBLE_LOCK,
LOCKDEP_ERR_DEAD_LOCK,
LOCKDEP_ERR_UNLOCK_WITHOUT_LOCK,
/* overflow, needs expand */
LOCKDEP_ERR_OVERFLOW,
};
/*<2A><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD> LockDepErrType<70><65><EFBFBD><EFBFBD><EFBFBD>ڱ<EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>п<EFBFBD><D0BF>ܷ<EFBFBD><DCB7><EFBFBD><EFBFBD>IJ<EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͡<EFBFBD><CDA1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǹ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD>ȡֵ<C8A1><D6B5><EFBFBD><EFBFBD>
LOCKDEP_SUCCESS<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>з<EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LOCKDEP_ERR_DOUBLE_LOCK<EFBFBD><EFBFBD><EFBFBD><EFBF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BD><EFBFBD><EFBFBD><EFBFBD>˽<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>֮ǰ<EFBFBD><EFBFBD>δ<EFBFBD>Զ<EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LOCKDEP_ERR_OVERFLOW<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󡣱<EFBFBD>ʾö<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡֵ<EFBFBD>Ѿ<EFBFBD><EFBFBD>޷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
typedef struct {
VOID *lockPtr;
VOID *lockAddr;
UINT64 waitTime;
UINT64 holdTime;
} HeldLocks;
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1B9B9><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Է<EFBFBD><D4B7><EFBFBD><EFBFBD>͵<EFBFBD><CDB5>Թ<EFBFBD><D4B9><EFBFBD><EFBFBD>м<EFBFBD>¼<EFBFBD><C2BC>ǰ<EFBFBD>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FBFBD><EFBFBD><EFBFBD><EFBFBD>и<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>*/
typedef struct {
VOID *waitLock;
INT32 lockDepth;
HeldLocks heldLocks[MAX_LOCK_DEPTH];
} LockDep;
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1B9B9><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Է<EFBFBD><D4B7><EFBFBD><EFBFBD>͵<EFBFBD><CDB5>Թ<EFBFBD><D4B9><EFBFBD><EFBFBD>м<EFBFBD>¼<EFBFBD><C2BC>ǰ<EFBFBD>̵߳<DFB3><CCB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5>
ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD>ǰ<EFBFBD>߳<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵȴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ε<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><EFBFBD>غͷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>DZ<EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
/**
* @ingroup los_lockdep
*
* @par Description:
* This API is used to check dead lock in spinlock.
* @attention
* <ul>
* <li>The parameter passed in should be ensured to be a legal pointer.</li>
* </ul>
*
* @param lock [IN] point to a SPIN_LOCK_S.
*
* @retval None.
* @par Dependency:
* <ul><li>los_lockdep.h: the header file that contains the API declaration.</li></ul>
* @see
* @since Huawei LiteOS V200R003C00
*/
extern VOID OsLockDepCheckIn(const SPIN_LOCK_S *lock);
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ OsLockDepCheckIn<49><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ const SPIN_LOCK_S* lock<63><6B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ VOID<49><44><EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǽ<EFBFBD>ָ<EFBFBD><D6B8>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> lock <EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Եķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD>ԡ<EFBFBD>*/
/**
* @ingroup los_lockdep
*
* @par Description:
* This API is used to trace when a spinlock locked.
* @attention
* <ul>
* <li>The parameter passed in should be ensured to be a legal pointer.</li>
* </ul>
*
* @param lock [IN] point to a SPIN_LOCK_S.
*
* @retval None.
* @par Dependency:
* <ul><li>los_lockdep.h: the header file that contains the API declaration.</li></ul>
* @see
* @since Huawei LiteOS V200R003C00
*/
extern VOID OsLockDepRecord(SPIN_LOCK_S *lock);
/**
* @ingroup los_lockdep
*
* @par Description:
* This API is used to trace when a spinlock unlocked.
* @attention
* <ul>
* <li>The parameter passed in should be ensured to be a legal pointer.</li>
* </ul>
*
* @param lock [IN] point to a SPIN_LOCK_S.
*
* @retval None.
* @par Dependency:
* <ul><li>los_lockdep.h: the header file that contains the API declaration.</li></ul>
* @see
* @since Huawei LiteOS V200R003C00
*/
extern VOID OsLockDepCheckOut(SPIN_LOCK_S *lock);
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ OsLockDepCheckOut<75><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ SPIN_LOCK_S* lock<63><6B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ VOID<49><44><EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD>Ǵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƴ<EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> lock<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ը<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Է<EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD>ԡ<EFBFBD>*/
/**
* @ingroup los_lockdep
*
* @par Description:
* This API is used to clear lockdep record of current task.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param None
* @retval None.
* @par Dependency:
* <ul><li>los_lockdep.h: the header file that contains the API declaration.</li></ul>
* @see
* @since Huawei LiteOS V200R003C00
*/
extern VOID OsLockdepClearSpinlocks(VOID);
#endif /* LOSCFG_KERNEL_SMP_LOCKDEP */
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif /* _LOS_LOCKDEP_H */