-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add preemptible work item APIs to cxplat library (#94)
* Add preemptible work item APIs to cxplat library * Fix symbol decoder if already in use by the process * Fix initialization bug in aligned allocate * Use INVALID_STATE error code Signed-off-by: Dave Thaler <[email protected]>
- Loading branch information
Showing
34 changed files
with
831 additions
and
418 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// SPDX-License-Identifier: MIT | ||
|
||
#if !defined(CMAKE_NUGET) | ||
#include <catch2/catch_all.hpp> | ||
#else | ||
#include <catch2/catch.hpp> | ||
#endif | ||
#include "cxplat.h" | ||
#include <windows.h> | ||
|
||
TEST_CASE("rundown_protection", "[rundown]") | ||
{ | ||
cxplat_rundown_reference_t rundown_reference; | ||
cxplat_initialize_rundown_protection(&rundown_reference); | ||
cxplat_acquire_rundown_protection(&rundown_reference); | ||
cxplat_release_rundown_protection(&rundown_reference); | ||
cxplat_wait_for_rundown_protection_release(&rundown_reference); | ||
|
||
cxplat_reinitialize_rundown_protection(&rundown_reference); | ||
cxplat_acquire_rundown_protection(&rundown_reference); | ||
cxplat_release_rundown_protection(&rundown_reference); | ||
cxplat_wait_for_rundown_protection_release(&rundown_reference); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// SPDX-License-Identifier: MIT | ||
|
||
#if !defined(CMAKE_NUGET) | ||
#include <catch2/catch_all.hpp> | ||
#else | ||
#include <catch2/catch.hpp> | ||
#endif | ||
#include "cxplat.h" | ||
#include <windows.h> | ||
|
||
static void | ||
_test_work_item_routine(_Inout_opt_ void* work_item_context) | ||
{ | ||
int* context = (int*)work_item_context; | ||
REQUIRE(*context == 1); | ||
(*context)++; | ||
} | ||
|
||
TEST_CASE("queue_preemptible_work_item", "[workitem]") | ||
{ | ||
REQUIRE(cxplat_initialize() == CXPLAT_STATUS_SUCCESS); | ||
|
||
cxplat_preemptible_work_item_t* work_item = nullptr; | ||
int context = 1; | ||
REQUIRE( | ||
cxplat_allocate_preemptible_work_item(nullptr, &work_item, _test_work_item_routine, &context) == | ||
CXPLAT_STATUS_SUCCESS); | ||
|
||
cxplat_queue_preemptible_work_item(work_item); | ||
cxplat_wait_for_preemptible_work_items_complete(); | ||
REQUIRE(context == 2); | ||
|
||
cxplat_cleanup(); | ||
} | ||
|
||
TEST_CASE("free_preemptible_work_item", "[workitem]") | ||
{ | ||
REQUIRE(cxplat_initialize() == CXPLAT_STATUS_SUCCESS); | ||
|
||
cxplat_preemptible_work_item_t* work_item = nullptr; | ||
int context = 1; | ||
REQUIRE( | ||
cxplat_allocate_preemptible_work_item(nullptr, &work_item, _test_work_item_routine, &context) == | ||
CXPLAT_STATUS_SUCCESS); | ||
cxplat_free_preemptible_work_item(work_item); | ||
REQUIRE(context == 1); | ||
|
||
cxplat_cleanup(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// SPDX-License-Identifier: MIT | ||
#pragma once | ||
#include "cxplat_platform.h" | ||
|
||
CXPLAT_EXTERN_C_BEGIN | ||
|
||
/** | ||
* @brief Initialize the rundown reference table entry for the given context. | ||
* | ||
* @param[in] context The address of a cxplat_rundown_reference_t structure. | ||
*/ | ||
void | ||
cxplat_initialize_rundown_protection(_Out_ cxplat_rundown_reference_t* rundown_reference); | ||
|
||
/** | ||
* @brief Reinitialize the rundown reference table entry for the given context. | ||
* | ||
* @param[in] context The address of a previously run down cxplat_rundown_reference_t structure. | ||
*/ | ||
void | ||
cxplat_reinitialize_rundown_protection(_Inout_ cxplat_rundown_reference_t* rundown_reference); | ||
|
||
/** | ||
* @brief Wait for the rundown reference count to reach 0 for the given context. | ||
* | ||
* @param[in] context The address of a cxplat_rundown_reference_t structure. | ||
*/ | ||
void | ||
cxplat_wait_for_rundown_protection_release(_Inout_ cxplat_rundown_reference_t* rundown_reference); | ||
|
||
/** | ||
* @brief Acquire a rundown reference for the given context. | ||
* | ||
* @param[in] context The address of a cxplat_rundown_reference_t structure. | ||
* @retval TRUE Rundown has not started. | ||
* @retval FALSE Rundown has started. | ||
*/ | ||
int | ||
cxplat_acquire_rundown_protection(_Inout_ cxplat_rundown_reference_t* rundown_reference); | ||
|
||
/** | ||
* @brief Release a rundown reference for the given context. | ||
* | ||
* @param[in] context The address of a cxplat_rundown_reference_t structure. | ||
*/ | ||
void | ||
cxplat_release_rundown_protection(_Inout_ cxplat_rundown_reference_t* rundown_reference); | ||
|
||
CXPLAT_EXTERN_C_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// SPDX-License-Identifier: MIT | ||
#pragma once | ||
|
||
CXPLAT_EXTERN_C_BEGIN | ||
|
||
typedef struct _cxplat_preemptible_work_item cxplat_preemptible_work_item_t; | ||
|
||
/** | ||
* @brief Create a preemptible work item. | ||
* | ||
* @param[in] caller_context Caller context, such as a DEVICE_OBJECT used to | ||
* create the work item. | ||
* @param[out] work_item Pointer to memory that will contain the pointer to | ||
* the preemptible work item on success. | ||
* @param[in] work_item_routine Routine to execute as a work item. | ||
* @param[in, out] work_item_context Context to pass to the routine. | ||
* @retval CXPLAT_STATUS_SUCCESS The operation was successful. | ||
* @retval CXPLAT_STATUS_NO_MEMORY Unable to allocate resources for this | ||
* work item. | ||
*/ | ||
_Must_inspect_result_ cxplat_status_t | ||
cxplat_allocate_preemptible_work_item( | ||
_In_opt_ void* caller_context, | ||
_Outptr_ cxplat_preemptible_work_item_t** work_item, | ||
_In_ void (*work_item_routine)(_Inout_opt_ void* work_item_context), | ||
_Inout_opt_ void* work_item_context); | ||
|
||
/** | ||
* @brief Queue a preemptible work item for execution. After execution, | ||
* it will automatically be freed. | ||
* | ||
* @param[in] work_item Pointer to the work item to execute and free. | ||
*/ | ||
void | ||
cxplat_queue_preemptible_work_item(_Inout_ cxplat_preemptible_work_item_t* work_item); | ||
|
||
/** | ||
* @brief Free a preemptible work item. | ||
* | ||
* @param[in] work_item Pointer to the work item to free. | ||
*/ | ||
void | ||
cxplat_free_preemptible_work_item(_Frees_ptr_opt_ cxplat_preemptible_work_item_t* work_item); | ||
|
||
/** | ||
* @brief Wait for all preemptible work items to complete. | ||
*/ | ||
void | ||
cxplat_wait_for_preemptible_work_items_complete(); | ||
|
||
CXPLAT_EXTERN_C_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// SPDX-License-Identifier: MIT | ||
|
||
// This file contains initialization/cleanup routines for the Windows kernel-mode cxplat library. | ||
#include "cxplat.h" | ||
|
||
cxplat_status_t | ||
cxplat_initialize() | ||
{ | ||
return CXPLAT_STATUS_SUCCESS; | ||
} | ||
|
||
void | ||
cxplat_cleanup() | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// SPDX-License-Identifier: MIT | ||
#include "cxplat.h" | ||
#include <ntddk.h> | ||
|
||
// TODO(issue #90): convert these to macros or inline functions | ||
void | ||
cxplat_initialize_rundown_protection(_Out_ cxplat_rundown_reference_t* rundown_reference) | ||
{ | ||
ExInitializeRundownProtection(rundown_reference); | ||
} | ||
|
||
void | ||
cxplat_reinitialize_rundown_protection(_Inout_ cxplat_rundown_reference_t* rundown_reference) | ||
{ | ||
ExReInitializeRundownProtection(rundown_reference); | ||
} | ||
|
||
void | ||
cxplat_wait_for_rundown_protection_release(_Inout_ cxplat_rundown_reference_t* rundown_reference) | ||
{ | ||
ExWaitForRundownProtectionRelease(rundown_reference); | ||
} | ||
|
||
int | ||
cxplat_acquire_rundown_protection(_Inout_ cxplat_rundown_reference_t* rundown_reference) | ||
{ | ||
return (int)ExAcquireRundownProtection(rundown_reference); | ||
} | ||
|
||
void | ||
cxplat_release_rundown_protection(_Inout_ cxplat_rundown_reference_t* rundown_reference) | ||
{ | ||
ExReleaseRundownProtection(rundown_reference); | ||
} | ||
|
Oops, something went wrong.