File: kmd_notify_properties.h

package info (click to toggle)
intel-compute-runtime 25.35.35096.9-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 79,324 kB
  • sloc: cpp: 926,243; lisp: 3,433; sh: 715; makefile: 162; python: 21
file content (71 lines) | stat: -rw-r--r-- 2,789 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * Copyright (C) 2018-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#pragma once
#include "shared/source/command_stream/task_count_helper.h"
#include "shared/source/command_stream/wait_status.h"

#include <atomic>
#include <cstdint>

namespace NEO {
enum QueueThrottle : uint32_t;
using FlushStamp = uint64_t;

struct KmdNotifyProperties {
    int64_t delayKmdNotifyMicroseconds;
    int64_t delayQuickKmdSleepMicroseconds;
    int64_t delayQuickKmdSleepForSporadicWaitsMicroseconds;
    int64_t delayQuickKmdSleepForDirectSubmissionMicroseconds;
    // Main switch for KMD Notify optimization - if its disabled, all below are disabled too
    bool enableKmdNotify;
    // Use smaller delay in specific situations (ie. from AsyncEventsHandler)
    bool enableQuickKmdSleep;
    // If waits are called sporadically  use QuickKmdSleep mode, otherwise use standard delay
    bool enableQuickKmdSleepForSporadicWaits;
    // If direct submission is enabled, use direct submission delay, otherwise use standard delay
    bool enableQuickKmdSleepForDirectSubmission;

    bool operator==(const KmdNotifyProperties &) const = default;
};

namespace KmdNotifyConstants {
inline constexpr int64_t timeoutInMicrosecondsForDisconnectedAcLine = 10000;
inline constexpr uint32_t minimumTaskCountDiffToCheckAcLine = 10;
} // namespace KmdNotifyConstants

class KmdNotifyHelper {
  public:
    KmdNotifyHelper() = delete;
    KmdNotifyHelper(const KmdNotifyProperties *properties) : properties(properties){};
    MOCKABLE_VIRTUAL ~KmdNotifyHelper() = default;

    WaitParams obtainTimeoutParams(bool quickKmdSleepRequest,
                                   TagAddressType currentHwTag,
                                   TaskCountType taskCountToWait,
                                   FlushStamp flushStampToWait,
                                   QueueThrottle throttle,
                                   bool kmdWaitModeActive,
                                   bool directSubmissionEnabled);

    bool quickKmdSleepForSporadicWaitsEnabled() const { return properties->enableQuickKmdSleepForSporadicWaits; }
    MOCKABLE_VIRTUAL void updateLastWaitForCompletionTimestamp();
    MOCKABLE_VIRTUAL void updateAcLineStatus();
    bool getAcLineConnected() const { return acLineConnected.load(); }

    static void overrideFromDebugVariable(int32_t debugVariableValue, int64_t &destination);
    static void overrideFromDebugVariable(int32_t debugVariableValue, bool &destination);

  protected:
    bool applyQuickKmdSleepForSporadicWait() const;
    int64_t getMicrosecondsSinceEpoch() const;

    const KmdNotifyProperties *properties = nullptr;
    std::atomic<int64_t> lastWaitForCompletionTimestampUs{0};
    std::atomic<bool> acLineConnected{true};
};
} // namespace NEO