| 111 | } |
| 112 | |
| 113 | XResult XQueueManager::AutoCreate(std::function<XResult(HwQueueHandle *)> create_hwq) |
| 114 | { |
| 115 | if (!GetEnvOption(XSCHED_AUTO_XQUEUE_ENV_NAME, false)) { |
| 116 | XDEBG("XQueue auto-create is disabled"); |
| 117 | return kXSchedSuccess; |
| 118 | } |
| 119 | HwCommandHandle hwq = 0; |
| 120 | XResult res = create_hwq(&hwq); |
| 121 | if (res != kXSchedSuccess) { |
| 122 | XWARN("fail to auto-create HwQueue, err: %d", res); |
| 123 | return res; |
| 124 | } |
| 125 | XDEBG("auto-created HwQueue 0x" FMT_64X, hwq); |
| 126 | XQueueHandle xq = 0; |
| 127 | XPreemptLevel level = XSCHED_DEFAULT_PREEMPT_LEVEL; |
| 128 | |
| 129 | // set level by env |
| 130 | int64_t env_int64 = 0; |
| 131 | bool env_set_level = GetEnvInt64(XSCHED_AUTO_XQUEUE_LEVEL_ENV_NAME, env_int64); |
| 132 | if (env_set_level) level = (XPreemptLevel)env_int64; |
| 133 | |
| 134 | res = XQueueCreate(&xq, hwq, level, kQueueCreateFlagNone); |
| 135 | if (res != kXSchedSuccess) { |
| 136 | XWARN("fail to auto-create XQueue (level-%d) for HwQueue 0x" FMT_64X ", err: %d", |
| 137 | level, hwq, res); |
| 138 | return res; |
| 139 | } |
| 140 | XDEBG("auto-created XQueue 0x" FMT_64X " (level-%d) for HwQueue 0x" FMT_64X, xq, level, hwq); |
| 141 | |
| 142 | // set launch config by env |
| 143 | int64_t env_threshold = -1; |
| 144 | int64_t env_batch_size = -1; |
| 145 | bool env_set_threshold = GetEnvInt64(XSCHED_AUTO_XQUEUE_THRESHOLD_ENV_NAME, env_threshold); |
| 146 | bool env_set_batch_size = GetEnvInt64(XSCHED_AUTO_XQUEUE_BATCH_SIZE_ENV_NAME, env_batch_size); |
| 147 | if (env_set_threshold || env_set_batch_size) { |
| 148 | res = XQueueSetLaunchConfig(xq, env_threshold, env_batch_size); |
| 149 | if (res != kXSchedSuccess) { |
| 150 | XWARN("fail to auto-set launch config [" FMT_64D ", " FMT_64D "] " |
| 151 | "for XQueue 0x" FMT_64X ", err: %d", env_threshold, env_batch_size, xq, res); |
| 152 | } |
| 153 | XDEBG("auto-set launch config [" FMT_64D ", " FMT_64D "] for XQueue 0x" FMT_64X, |
| 154 | env_threshold, env_batch_size, xq); |
| 155 | } |
| 156 | |
| 157 | // set priority by env |
| 158 | int64_t env_priority = PRIORITY_DEFAULT; |
| 159 | if (GetEnvInt64(XSCHED_AUTO_XQUEUE_PRIORITY_ENV_NAME, env_priority)) { |
| 160 | res = XHintPriority(xq, env_priority); |
| 161 | if (res != kXSchedSuccess) { |
| 162 | XWARN("fail to auto-set priority " FMT_64D " for XQueue 0x" FMT_64X ", err: %d", |
| 163 | env_priority, xq, res); |
| 164 | } |
| 165 | XDEBG("auto-set priority " FMT_64D " for XQueue 0x" FMT_64X, env_priority, xq); |
| 166 | } |
| 167 | |
| 168 | // set utilization by env |
| 169 | int64_t env_utilization; |
| 170 | if (GetEnvInt64(XSCHED_AUTO_XQUEUE_UTILIZATION_ENV_NAME, env_utilization)) { |
nothing calls this directly
no test coverage detected