Skip to content

Commit fffd56d

Browse files
refactor: bind drm context within IoctlHelper::createDrmContext method
Related-To: NEO-6999 Signed-off-by: Mateusz Jablonski <[email protected]>
1 parent efa19a0 commit fffd56d

File tree

11 files changed

+23
-18
lines changed

11 files changed

+23
-18
lines changed

opencl/test/unit_test/aub_tests/command_stream/aub_command_stream_tests.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2021 Intel Corporation
2+
* Copyright (C) 2018-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -11,6 +11,7 @@
1111
#include "shared/source/helpers/ptr_math.h"
1212
#include "shared/source/os_interface/os_context.h"
1313
#include "shared/test/common/cmd_parse/gen_cmd_parse.h"
14+
#include "shared/test/common/mocks/mock_os_context.h"
1415
#include "shared/test/common/test_macros/test.h"
1516

1617
#include "opencl/test/unit_test/command_queue/command_queue_fixture.h"
@@ -43,7 +44,7 @@ struct AUBFixture : public AUBCommandStreamFixture,
4344

4445
template <typename FamilyType>
4546
void testNoopIdXcs(aub_stream::EngineType engineType) {
46-
pCommandStreamReceiver->getOsContext().getEngineType() = engineType;
47+
static_cast<MockOsContext &>(pCommandStreamReceiver->getOsContext()).engineType = engineType;
4748

4849
typedef typename FamilyType::MI_NOOP MI_NOOP;
4950

shared/source/helpers/engine_control.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2021 Intel Corporation
2+
* Copyright (C) 2018-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -22,7 +22,7 @@ struct EngineControl {
2222
CommandStreamReceiver *commandStreamReceiver = nullptr;
2323
OsContext *osContext = nullptr;
2424

25-
aub_stream::EngineType &getEngineType() const { return osContext->getEngineType(); }
25+
const aub_stream::EngineType &getEngineType() const { return osContext->getEngineType(); }
2626
EngineUsage getEngineUsage() const { return osContext->getEngineUsage(); }
2727
};
2828
} // namespace NEO

shared/source/os_interface/linux/ioctl_helper.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "shared/source/helpers/ptr_math.h"
1515
#include "shared/source/os_interface/linux/drm_neo.h"
1616
#include "shared/source/os_interface/linux/drm_wrappers.h"
17-
#include "shared/source/os_interface/os_context.h"
17+
#include "shared/source/os_interface/linux/os_context_linux.h"
1818

1919
#include "drm/i915_drm.h"
2020

@@ -82,7 +82,7 @@ void IoctlHelper::logExecBuffer(const ExecBuffer &execBuffer, std::stringstream
8282
<< " }\n";
8383
}
8484

85-
uint32_t IoctlHelper::createDrmContext(Drm &drm, const OsContext &osContext, uint32_t drmVmId) {
85+
uint32_t IoctlHelper::createDrmContext(Drm &drm, OsContextLinux &osContext, uint32_t drmVmId, uint32_t deviceIndex) {
8686

8787
const auto numberOfCCS = drm.getRootDeviceEnvironment().getHardwareInfo()->gtSystemInfo.CCSInfo.NumberOfCCSEnabled;
8888
const bool debuggableContext = drm.isContextDebugSupported() && drm.getRootDeviceEnvironment().executionEnvironment.isDebuggingEnabled() && !osContext.isInternalEngine();
@@ -103,6 +103,8 @@ uint32_t IoctlHelper::createDrmContext(Drm &drm, const OsContext &osContext, uin
103103
if (drm.isPreemptionSupported() && osContext.isLowPriority()) {
104104
drm.setLowPriorityContextParam(drmContextId);
105105
}
106+
auto engineFlag = drm.bindDrmContext(drmContextId, deviceIndex, osContext.getEngineType(), osContext.isEngineInstanced());
107+
osContext.setEngineFlag(engineFlag);
106108
return drmContextId;
107109
}
108110

shared/source/os_interface/linux/ioctl_helper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
namespace NEO {
2222
class Drm;
23-
class OsContext;
23+
class OsContextLinux;
2424
class IoctlHelper;
2525
enum class CacheRegion : uint16_t;
2626
struct HardwareInfo;
@@ -114,7 +114,7 @@ class IoctlHelper {
114114

115115
virtual std::vector<MemoryRegion> translateToMemoryRegions(const std::vector<uint8_t> &regionInfo);
116116

117-
uint32_t createDrmContext(Drm &drm, const OsContext &osContext, uint32_t drmVmId);
117+
uint32_t createDrmContext(Drm &drm, OsContextLinux &osContext, uint32_t drmVmId, uint32_t deviceIndex);
118118
std::vector<EngineCapabilities> translateToEngineCaps(const std::vector<uint8_t> &data);
119119

120120
void fillExecObject(ExecObject &execObject, uint32_t handle, uint64_t gpuAddress, uint32_t drmContextId, bool bindInfo, bool isMarkedForCapture);

shared/source/os_interface/linux/os_context_linux.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ void OsContextLinux::initializeContext() {
4848
for (auto deviceIndex = 0u; deviceIndex < deviceBitfield.size(); deviceIndex++) {
4949
if (deviceBitfield.test(deviceIndex)) {
5050
auto drmVmId = drm.getVirtualMemoryAddressSpace(deviceIndex);
51-
auto drmContextId = drm.getIoctlHelper()->createDrmContext(drm, *this, drmVmId);
51+
auto drmContextId = drm.getIoctlHelper()->createDrmContext(drm, *this, drmVmId, deviceIndex);
5252

53-
this->engineFlag = drm.bindDrmContext(drmContextId, deviceIndex, engineType, isEngineInstanced());
5453
this->drmContextIds.push_back(drmContextId);
5554

5655
if (drm.isPerContextVMRequired()) {

shared/source/os_interface/linux/os_context_linux.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class OsContextLinux : public OsContext {
2121
OsContextLinux(Drm &drm, uint32_t contextId, const EngineDescriptor &engineDescriptor);
2222

2323
unsigned int getEngineFlag() const { return engineFlag; }
24+
void setEngineFlag(unsigned int engineFlag) { this->engineFlag = engineFlag; }
2425
const std::vector<uint32_t> &getDrmContextIds() const { return drmContextIds; }
2526
const std::vector<uint32_t> &getDrmVmIds() const { return drmVmIds; }
2627
void setNewResourceBound(bool value) { this->newResourceBound = value; };

shared/source/os_interface/os_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class OsContext : public ReferenceTrackedObject<OsContext> {
3535
uint32_t getNumSupportedDevices() const { return numSupportedDevices; }
3636
DeviceBitfield getDeviceBitfield() const { return deviceBitfield; }
3737
PreemptionMode getPreemptionMode() const { return preemptionMode; }
38-
aub_stream::EngineType &getEngineType() { return engineType; }
38+
const aub_stream::EngineType &getEngineType() const { return engineType; }
3939
EngineUsage getEngineUsage() { return engineUsage; }
4040
bool isRegular() const { return engineUsage == EngineUsage::Regular; }
4141
bool isLowPriority() const { return engineUsage == EngineUsage::LowPriority; }

shared/test/common/mocks/mock_os_context.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ class MockOsContext : public OsContext {
1919
MockOsContext(uint32_t contextId, const EngineDescriptor &engineDescriptorHelper)
2020
: OsContext(contextId, engineDescriptorHelper) {}
2121
};
22+
static_assert(sizeof(OsContext) == sizeof(MockOsContext));
2223
} // namespace NEO

shared/test/unit_test/command_stream/aub_command_stream_receiver_1_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,8 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon
11201120
HWTEST_F(AubCommandStreamReceiverTests, WhenBlitBufferIsCalledThenCounterIsCorrectlyIncremented) {
11211121
auto aubExecutionEnvironment = getEnvironment<UltAubCommandStreamReceiver<FamilyType>>(true, true, true);
11221122
auto aubCsr = aubExecutionEnvironment->template getCsr<UltAubCommandStreamReceiver<FamilyType>>();
1123-
aubCsr->osContext->getEngineType() = aub_stream::ENGINE_BCS;
1123+
auto osContext = static_cast<MockOsContext *>(aubCsr->osContext);
1124+
osContext->engineType = aub_stream::ENGINE_BCS;
11241125
EXPECT_EQ(0u, aubCsr->blitBufferCalled);
11251126

11261127
MockGraphicsAllocation allocation(reinterpret_cast<void *>(0x1000), 0);

shared/test/unit_test/command_stream/aub_command_stream_receiver_3_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationDumpableWhenDumpA
431431
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
432432
gfxAllocation->setDefaultGmm(new Gmm(pDevice->executionEnvironment->rootDeviceEnvironments[0]->getGmmHelper(), nullptr, 1, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, false, {}, true));
433433

434-
auto &csrOsContext = aubCsr.getOsContext();
434+
auto &csrOsContext = static_cast<MockOsContext &>(aubCsr.getOsContext());
435435

436436
{
437437
// Non-BCS engine, BCS dump
@@ -458,7 +458,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationDumpableWhenDumpA
458458

459459
{
460460
// BCS engine, Non-BCS dump
461-
csrOsContext.getEngineType() = aub_stream::EngineType::ENGINE_BCS;
461+
csrOsContext.engineType = aub_stream::EngineType::ENGINE_BCS;
462462
EXPECT_TRUE(EngineHelpers::isBcs(csrOsContext.getEngineType()));
463463
gfxAllocation->setAllocDumpable(true, false);
464464

@@ -470,7 +470,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationDumpableWhenDumpA
470470

471471
{
472472
// BCS engine, BCS dump
473-
csrOsContext.getEngineType() = aub_stream::EngineType::ENGINE_BCS;
473+
csrOsContext.engineType = aub_stream::EngineType::ENGINE_BCS;
474474
EXPECT_TRUE(EngineHelpers::isBcs(csrOsContext.getEngineType()));
475475
gfxAllocation->setAllocDumpable(true, true);
476476

0 commit comments

Comments
 (0)