Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 1 | /* |
Kristofer Jonsson | 3c6a260 | 2022-03-10 11:17:29 +0100 | [diff] [blame] | 2 | * Copyright (c) 2020,2022 Arm Limited. |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 3 | * |
| 4 | * This program is free software and is provided to you under the terms of the |
| 5 | * GNU General Public License version 2 as published by the Free Software |
| 6 | * Foundation, and any use by you of this program is subject to the terms |
| 7 | * of such GNU licence. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, you can access it online at |
| 16 | * http://www.gnu.org/licenses/gpl-2.0.html. |
| 17 | * |
| 18 | * SPDX-License-Identifier: GPL-2.0-only |
| 19 | */ |
| 20 | |
| 21 | /**************************************************************************** |
| 22 | * Includes |
| 23 | ****************************************************************************/ |
| 24 | |
| 25 | #include "ethosu_inference.h" |
| 26 | |
| 27 | #include "ethosu_buffer.h" |
| 28 | #include "ethosu_core_interface.h" |
| 29 | #include "ethosu_device.h" |
| 30 | #include "ethosu_network.h" |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 31 | |
| 32 | #include <linux/anon_inodes.h> |
| 33 | #include <linux/file.h> |
| 34 | #include <linux/fs.h> |
| 35 | #include <linux/poll.h> |
| 36 | |
| 37 | /**************************************************************************** |
| 38 | * Variables |
| 39 | ****************************************************************************/ |
| 40 | |
| 41 | static int ethosu_inference_release(struct inode *inode, |
| 42 | struct file *file); |
| 43 | |
| 44 | static unsigned int ethosu_inference_poll(struct file *file, |
| 45 | poll_table *wait); |
| 46 | |
| 47 | static long ethosu_inference_ioctl(struct file *file, |
| 48 | unsigned int cmd, |
| 49 | unsigned long arg); |
| 50 | |
| 51 | static const struct file_operations ethosu_inference_fops = { |
| 52 | .release = ðosu_inference_release, |
| 53 | .poll = ðosu_inference_poll, |
| 54 | .unlocked_ioctl = ðosu_inference_ioctl, |
| 55 | #ifdef CONFIG_COMPAT |
| 56 | .compat_ioctl = ðosu_inference_ioctl, |
| 57 | #endif |
| 58 | }; |
| 59 | |
| 60 | /**************************************************************************** |
| 61 | * Functions |
| 62 | ****************************************************************************/ |
| 63 | |
| 64 | static const char *status_to_string(const enum ethosu_uapi_status status) |
| 65 | { |
| 66 | switch (status) { |
| 67 | case ETHOSU_UAPI_STATUS_OK: { |
| 68 | return "Ok"; |
| 69 | } |
| 70 | case ETHOSU_UAPI_STATUS_ERROR: { |
| 71 | return "Error"; |
| 72 | } |
Davide Grohmann | 82d2258 | 2022-04-25 12:52:38 +0200 | [diff] [blame^] | 73 | case ETHOSU_UAPI_STATUS_RUNNING: { |
| 74 | return "Running"; |
| 75 | } |
| 76 | case ETHOSU_UAPI_STATUS_REJECTED: { |
| 77 | return "Rejected"; |
| 78 | } |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 79 | default: { |
| 80 | return "Unknown"; |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | static int ethosu_inference_send(struct ethosu_inference *inf) |
| 86 | { |
| 87 | int ret; |
| 88 | |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 89 | inf->status = ETHOSU_UAPI_STATUS_ERROR; |
| 90 | |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 91 | ret = ethosu_mailbox_inference(&inf->edev->mailbox, inf, |
| 92 | inf->ifm_count, inf->ifm, |
| 93 | inf->ofm_count, inf->ofm, |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 94 | inf->net->buf, |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 95 | inf->net->index, |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 96 | inf->pmu_event_config, |
| 97 | ETHOSU_PMU_EVENT_MAX, |
| 98 | inf->pmu_cycle_counter_enable); |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 99 | if (ret) |
| 100 | return ret; |
| 101 | |
Davide Grohmann | 82d2258 | 2022-04-25 12:52:38 +0200 | [diff] [blame^] | 102 | inf->status = ETHOSU_UAPI_STATUS_RUNNING; |
| 103 | |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 104 | ethosu_inference_get(inf); |
| 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 109 | static void ethosu_inference_fail(struct ethosu_mailbox_msg *msg) |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 110 | { |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 111 | struct ethosu_inference *inf = |
| 112 | container_of(msg, typeof(*inf), msg); |
| 113 | int ret; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 114 | |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 115 | /* Decrement reference count if inference was pending reponse */ |
| 116 | if (!inf->done) { |
| 117 | ret = ethosu_inference_put(inf); |
| 118 | if (ret) |
| 119 | return; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 120 | } |
| 121 | |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 122 | /* Fail inference and wake up any waiting process */ |
| 123 | inf->status = ETHOSU_UAPI_STATUS_ERROR; |
| 124 | inf->done = true; |
| 125 | wake_up_interruptible(&inf->waitq); |
| 126 | } |
| 127 | |
| 128 | static int ethosu_inference_resend(struct ethosu_mailbox_msg *msg) |
| 129 | { |
| 130 | struct ethosu_inference *inf = |
| 131 | container_of(msg, typeof(*inf), msg); |
| 132 | int ret; |
| 133 | |
| 134 | /* Don't resend request if response has already been received */ |
| 135 | if (inf->done) |
| 136 | return 0; |
| 137 | |
| 138 | /* Decrement reference count for pending request */ |
| 139 | ret = ethosu_inference_put(inf); |
| 140 | if (ret) |
| 141 | return 0; |
| 142 | |
| 143 | /* Resend request */ |
| 144 | ret = ethosu_inference_send(inf); |
| 145 | if (ret) |
| 146 | return ret; |
| 147 | |
| 148 | return 0; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | static bool ethosu_inference_verify(struct file *file) |
| 152 | { |
| 153 | return file->f_op == ðosu_inference_fops; |
| 154 | } |
| 155 | |
| 156 | static void ethosu_inference_kref_destroy(struct kref *kref) |
| 157 | { |
| 158 | struct ethosu_inference *inf = |
| 159 | container_of(kref, struct ethosu_inference, kref); |
| 160 | |
| 161 | dev_info(inf->edev->dev, |
| 162 | "Inference destroy. handle=0x%pK, status=%d\n", |
| 163 | inf, inf->status); |
| 164 | |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 165 | list_del(&inf->msg.list); |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 166 | |
| 167 | while (inf->ifm_count-- > 0) |
| 168 | ethosu_buffer_put(inf->ifm[inf->ifm_count]); |
| 169 | |
| 170 | while (inf->ofm_count-- > 0) |
| 171 | ethosu_buffer_put(inf->ofm[inf->ofm_count]); |
| 172 | |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 173 | ethosu_network_put(inf->net); |
| 174 | devm_kfree(inf->edev->dev, inf); |
| 175 | } |
| 176 | |
| 177 | static int ethosu_inference_release(struct inode *inode, |
| 178 | struct file *file) |
| 179 | { |
| 180 | struct ethosu_inference *inf = file->private_data; |
| 181 | |
| 182 | dev_info(inf->edev->dev, |
| 183 | "Inference release. handle=0x%pK, status=%d\n", |
| 184 | inf, inf->status); |
| 185 | |
| 186 | ethosu_inference_put(inf); |
| 187 | |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | static unsigned int ethosu_inference_poll(struct file *file, |
| 192 | poll_table *wait) |
| 193 | { |
| 194 | struct ethosu_inference *inf = file->private_data; |
| 195 | int ret = 0; |
| 196 | |
| 197 | poll_wait(file, &inf->waitq, wait); |
| 198 | |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 199 | if (inf->done) |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 200 | ret |= POLLIN; |
| 201 | |
| 202 | return ret; |
| 203 | } |
| 204 | |
| 205 | static long ethosu_inference_ioctl(struct file *file, |
| 206 | unsigned int cmd, |
| 207 | unsigned long arg) |
| 208 | { |
| 209 | struct ethosu_inference *inf = file->private_data; |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 210 | void __user *udata = (void __user *)arg; |
| 211 | int ret; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 212 | |
| 213 | ret = mutex_lock_interruptible(&inf->edev->mutex); |
| 214 | if (ret) |
| 215 | return ret; |
| 216 | |
| 217 | dev_info(inf->edev->dev, "Ioctl: cmd=%u, arg=%lu\n", cmd, arg); |
| 218 | |
| 219 | switch (cmd) { |
| 220 | case ETHOSU_IOCTL_INFERENCE_STATUS: { |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 221 | struct ethosu_uapi_result_status uapi; |
| 222 | int i; |
| 223 | |
| 224 | uapi.status = inf->status; |
| 225 | |
| 226 | for (i = 0; i < ETHOSU_PMU_EVENT_MAX; i++) { |
| 227 | uapi.pmu_config.events[i] = |
| 228 | inf->pmu_event_config[i]; |
| 229 | uapi.pmu_count.events[i] = |
| 230 | inf->pmu_event_count[i]; |
| 231 | } |
| 232 | |
| 233 | uapi.pmu_config.cycle_count = inf->pmu_cycle_counter_enable; |
| 234 | uapi.pmu_count.cycle_count = inf->pmu_cycle_counter_count; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 235 | |
| 236 | dev_info(inf->edev->dev, |
| 237 | "Ioctl: Inference status. status=%s (%d)\n", |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 238 | status_to_string(uapi.status), uapi.status); |
| 239 | |
| 240 | ret = copy_to_user(udata, &uapi, sizeof(uapi)) ? -EFAULT : 0; |
| 241 | |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 242 | break; |
| 243 | } |
| 244 | default: { |
| 245 | dev_err(inf->edev->dev, "Invalid ioctl. cmd=%u, arg=%lu", |
| 246 | cmd, arg); |
| 247 | break; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | mutex_unlock(&inf->edev->mutex); |
| 252 | |
| 253 | return ret; |
| 254 | } |
| 255 | |
| 256 | int ethosu_inference_create(struct ethosu_device *edev, |
| 257 | struct ethosu_network *net, |
| 258 | struct ethosu_uapi_inference_create *uapi) |
| 259 | { |
| 260 | struct ethosu_inference *inf; |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 261 | uint32_t i; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 262 | int fd; |
| 263 | int ret = -ENOMEM; |
| 264 | |
| 265 | inf = devm_kzalloc(edev->dev, sizeof(*inf), GFP_KERNEL); |
| 266 | if (!inf) |
| 267 | return -ENOMEM; |
| 268 | |
| 269 | inf->edev = edev; |
| 270 | inf->net = net; |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 271 | inf->done = false; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 272 | inf->status = ETHOSU_UAPI_STATUS_ERROR; |
| 273 | kref_init(&inf->kref); |
| 274 | init_waitqueue_head(&inf->waitq); |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 275 | inf->msg.fail = ethosu_inference_fail; |
| 276 | inf->msg.resend = ethosu_inference_resend; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 277 | |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 278 | /* Get pointer to IFM buffers */ |
| 279 | for (i = 0; i < uapi->ifm_count; i++) { |
| 280 | inf->ifm[i] = ethosu_buffer_get_from_fd(uapi->ifm_fd[i]); |
| 281 | if (IS_ERR(inf->ifm[i])) { |
| 282 | ret = PTR_ERR(inf->ifm[i]); |
| 283 | goto put_ifm; |
| 284 | } |
| 285 | |
| 286 | inf->ifm_count++; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | /* Get pointer to OFM buffer */ |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 290 | for (i = 0; i < uapi->ofm_count; i++) { |
| 291 | inf->ofm[i] = ethosu_buffer_get_from_fd(uapi->ofm_fd[i]); |
| 292 | if (IS_ERR(inf->ofm[i])) { |
| 293 | ret = PTR_ERR(inf->ofm[i]); |
| 294 | goto put_ofm; |
| 295 | } |
| 296 | |
| 297 | inf->ofm_count++; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 298 | } |
| 299 | |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 300 | /* Configure PMU and cycle counter */ |
| 301 | dev_info(inf->edev->dev, |
| 302 | "Configuring events for PMU. events=[%u, %u, %u, %u]\n", |
| 303 | uapi->pmu_config.events[0], uapi->pmu_config.events[1], |
| 304 | uapi->pmu_config.events[2], uapi->pmu_config.events[3]); |
| 305 | |
| 306 | /* Configure events and reset count for all events */ |
| 307 | for (i = 0; i < ETHOSU_PMU_EVENT_MAX; i++) { |
| 308 | inf->pmu_event_config[i] = uapi->pmu_config.events[i]; |
| 309 | inf->pmu_event_count[i] = 0; |
| 310 | } |
| 311 | |
| 312 | if (uapi->pmu_config.cycle_count) |
| 313 | dev_info(inf->edev->dev, "Enabling cycle counter\n"); |
| 314 | |
| 315 | /* Configure cycle counter and reset any previous count */ |
| 316 | inf->pmu_cycle_counter_enable = uapi->pmu_config.cycle_count; |
| 317 | inf->pmu_cycle_counter_count = 0; |
| 318 | |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 319 | /* Increment network reference count */ |
| 320 | ethosu_network_get(net); |
| 321 | |
| 322 | /* Create file descriptor */ |
| 323 | ret = fd = anon_inode_getfd("ethosu-inference", ðosu_inference_fops, |
| 324 | inf, O_RDWR | O_CLOEXEC); |
| 325 | if (ret < 0) |
| 326 | goto put_net; |
| 327 | |
| 328 | /* Store pointer to file structure */ |
| 329 | inf->file = fget(ret); |
| 330 | fput(inf->file); |
| 331 | |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 332 | /* Add inference to pending list */ |
| 333 | list_add(&inf->msg.list, &edev->mailbox.pending_list); |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 334 | |
| 335 | /* Send inference request to Arm Ethos-U subsystem */ |
| 336 | (void)ethosu_inference_send(inf); |
| 337 | |
| 338 | dev_info(edev->dev, "Inference create. handle=0x%pK, fd=%d", |
| 339 | inf, fd); |
| 340 | |
| 341 | return fd; |
| 342 | |
| 343 | put_net: |
| 344 | ethosu_network_put(inf->net); |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 345 | |
| 346 | put_ofm: |
| 347 | while (inf->ofm_count-- > 0) |
| 348 | ethosu_buffer_put(inf->ofm[inf->ofm_count]); |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 349 | |
| 350 | put_ifm: |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 351 | while (inf->ifm_count-- > 0) |
| 352 | ethosu_buffer_put(inf->ifm[inf->ifm_count]); |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 353 | |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 354 | devm_kfree(edev->dev, inf); |
| 355 | |
| 356 | return ret; |
| 357 | } |
| 358 | |
| 359 | struct ethosu_inference *ethosu_inference_get_from_fd(int fd) |
| 360 | { |
| 361 | struct ethosu_inference *inf; |
| 362 | struct file *file; |
| 363 | |
| 364 | file = fget(fd); |
| 365 | if (!file) |
| 366 | return ERR_PTR(-EINVAL); |
| 367 | |
| 368 | if (!ethosu_inference_verify(file)) { |
| 369 | fput(file); |
| 370 | |
| 371 | return ERR_PTR(-EINVAL); |
| 372 | } |
| 373 | |
| 374 | inf = file->private_data; |
| 375 | ethosu_inference_get(inf); |
| 376 | fput(file); |
| 377 | |
| 378 | return inf; |
| 379 | } |
| 380 | |
| 381 | void ethosu_inference_get(struct ethosu_inference *inf) |
| 382 | { |
| 383 | kref_get(&inf->kref); |
| 384 | } |
| 385 | |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 386 | int ethosu_inference_put(struct ethosu_inference *inf) |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 387 | { |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 388 | return kref_put(&inf->kref, ðosu_inference_kref_destroy); |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | void ethosu_inference_rsp(struct ethosu_device *edev, |
| 392 | struct ethosu_core_inference_rsp *rsp) |
| 393 | { |
| 394 | struct ethosu_inference *inf = |
| 395 | (struct ethosu_inference *)rsp->user_arg; |
| 396 | int ret; |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 397 | int i; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 398 | |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 399 | ret = ethosu_mailbox_find(&edev->mailbox, &inf->msg); |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 400 | if (ret) { |
| 401 | dev_warn(edev->dev, |
| 402 | "Handle not found in inference list. handle=0x%p\n", |
| 403 | rsp); |
| 404 | |
| 405 | return; |
| 406 | } |
| 407 | |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 408 | if (rsp->status == ETHOSU_CORE_STATUS_OK && |
| 409 | inf->ofm_count <= ETHOSU_CORE_BUFFER_MAX) { |
| 410 | uint32_t i; |
| 411 | |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 412 | inf->status = ETHOSU_UAPI_STATUS_OK; |
| 413 | |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 414 | for (i = 0; i < inf->ofm_count; i++) { |
| 415 | struct ethosu_buffer *ofm = inf->ofm[i]; |
| 416 | |
| 417 | ret = ethosu_buffer_resize( |
| 418 | ofm, ofm->size + rsp->ofm_size[i], |
| 419 | ofm->offset); |
| 420 | if (ret) |
| 421 | inf->status = ETHOSU_UAPI_STATUS_ERROR; |
| 422 | } |
Davide Grohmann | 82d2258 | 2022-04-25 12:52:38 +0200 | [diff] [blame^] | 423 | } else if (rsp->status == ETHOSU_CORE_STATUS_REJECTED) { |
| 424 | inf->status = ETHOSU_UAPI_STATUS_REJECTED; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 425 | } else { |
| 426 | inf->status = ETHOSU_UAPI_STATUS_ERROR; |
| 427 | } |
| 428 | |
Davide Grohmann | 82d2258 | 2022-04-25 12:52:38 +0200 | [diff] [blame^] | 429 | if (inf->status == ETHOSU_UAPI_STATUS_OK) { |
| 430 | for (i = 0; i < ETHOSU_CORE_PMU_MAX; i++) { |
| 431 | inf->pmu_event_config[i] = rsp->pmu_event_config[i]; |
| 432 | inf->pmu_event_count[i] = rsp->pmu_event_count[i]; |
| 433 | } |
| 434 | |
| 435 | inf->pmu_cycle_counter_enable = rsp->pmu_cycle_counter_enable; |
| 436 | inf->pmu_cycle_counter_count = rsp->pmu_cycle_counter_count; |
| 437 | |
| 438 | dev_info(edev->dev, |
| 439 | "PMU events. config=[%u, %u, %u, %u], count=[%u, %u, %u, %u]\n", |
| 440 | inf->pmu_event_config[0], inf->pmu_event_config[1], |
| 441 | inf->pmu_event_config[2], inf->pmu_event_config[3], |
| 442 | inf->pmu_event_count[0], inf->pmu_event_count[1], |
| 443 | inf->pmu_event_count[2], inf->pmu_event_count[3]); |
| 444 | |
| 445 | dev_info(edev->dev, |
| 446 | "PMU cycle counter. enable=%u, count=%llu\n", |
| 447 | inf->pmu_cycle_counter_enable, |
| 448 | inf->pmu_cycle_counter_count); |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 449 | } |
| 450 | |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 451 | inf->done = true; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 452 | wake_up_interruptible(&inf->waitq); |
| 453 | |
| 454 | ethosu_inference_put(inf); |
| 455 | } |