aciodrv: refactor to support multiple active drivers (with specified ports) - [merged] #178

Closed
opened 2021-01-14 10:23:49 +03:00 by icex2 · 53 comments
icex2 commented 2021-01-14 10:23:49 +03:00 (Migrated from github.com)

In GitLab by @xyen on Jan 14, 2021, 08:23

Merges aciodrv_refactor -> master

Refactors aciodrv and related systems to support multiple active ports.

Tested with a SDVX BIO2 and ICCA in aciotest.

This sets the groundwork for aciomgr, which will allow multiple clients to share the same active port.

In GitLab by @xyen on Jan 14, 2021, 08:23 _Merges aciodrv_refactor -> master_ Refactors aciodrv and related systems to support multiple active ports. Tested with a SDVX BIO2 and ICCA in aciotest. This sets the groundwork for aciomgr, which will allow multiple clients to share the same active port.
icex2 commented 2021-01-14 21:57:50 +03:00 (Migrated from github.com)

In GitLab by @xyen on Jan 14, 2021, 19:57

added 29 commits

  • a29ee3c0...f945a2d3 - 27 commits from branch master
  • 241f0f65 - aciodrv: refactor to support multiple active drivers (with specified ports)
  • 4cba227d - aciodrv: support multi-sized response packets by divining the packet size

Compare with previous version

In GitLab by @xyen on Jan 14, 2021, 19:57 added 29 commits <ul><li>a29ee3c0...f945a2d3 - 27 commits from branch <code>master</code></li><li>241f0f65 - aciodrv: refactor to support multiple active drivers (with specified ports)</li><li>4cba227d - aciodrv: support multi-sized response packets by divining the packet size</li></ul> [Compare with previous version](/djhackers/bemanitools/-/merge_requests/77/diffs?diff_id=1447&start_sha=a29ee3c0358810c2bf5e7d0e9d02e2a4dc9d97e9)
icex2 commented 2021-01-14 22:06:51 +03:00 (Migrated from github.com)

In GitLab by @xyen on Jan 14, 2021, 20:06

added 1 commit

  • 841d3406 - aciodrv: fix pointer format, and missing close context

Compare with previous version

In GitLab by @xyen on Jan 14, 2021, 20:06 added 1 commit <ul><li>841d3406 - aciodrv: fix pointer format, and missing close context</li></ul> [Compare with previous version](/djhackers/bemanitools/-/merge_requests/77/diffs?diff_id=1448&start_sha=4cba227d1cd8c666c7a1de374ebe68ca42029194)
icex2 commented 2021-01-16 17:56:48 +03:00 (Migrated from github.com)

Suggestion for "magic numbers": Move them to defines to make them more self explanatory, e.g. #define ACIO_MAX_NODES 16. I would also suggest move the 4 to a #define ACIO_NODE_PRODUCT_CODE_LEN 4

Suggestion for "magic numbers": Move them to defines to make them more self explanatory, e.g. `#define ACIO_MAX_NODES 16`. I would also suggest move the `4` to a `#define ACIO_NODE_PRODUCT_CODE_LEN 4`
icex2 commented 2021-01-16 17:58:31 +03:00 (Migrated from github.com)

👍 for not exposing the internal structure.

:thumbsup: for not exposing the internal structure.
icex2 commented 2021-01-16 17:59:24 +03:00 (Migrated from github.com)

Nit: Magic number like in the module. The define for the needs to move to the header here.

Nit: Magic number like in the module. The define for the needs to move to the header here.
icex2 commented 2021-01-16 18:01:13 +03:00 (Migrated from github.com)

Can you adapt the various log parts guarded by AC_IO_MSG_LOG to include printing the fd? e.g. log_info("[%X] Beginning recv: (%d b)", device->fd, resp_size);

Can you adapt the various log parts guarded by `AC_IO_MSG_LOG` to include printing the fd? e.g. `log_info("[%X] Beginning recv: (%d b)", device->fd, resp_size);`
icex2 commented 2021-01-16 18:01:59 +03:00 (Migrated from github.com)

Here we also need to print the fd to be able to idenfity multiple devices in the logs.

Here we also need to print the `fd` to be able to idenfity multiple devices in the logs.
icex2 commented 2021-01-16 18:03:21 +03:00 (Migrated from github.com)

To improve tracability, add a log_debug("[%X] Closing acio device", device->fd);.

Also, please guard against NULLs on function entry with log_assert(device); -> Apply to other functions as well.

To improve tracability, add a `log_debug("[%X] Closing acio device", device->fd);`. Also, please guard against NULLs on function entry with `log_assert(device);` -> Apply to other functions as well.
icex2 commented 2021-01-16 18:03:52 +03:00 (Migrated from github.com)

Replace magic number 4 with define from above.

Replace magic number `4` with define from above.
icex2 commented 2021-01-16 18:06:14 +03:00 (Migrated from github.com)

For traceability, add a log_debug("[%X] acio device opened, path %s, baud %d", device->fd, port_path, baud);.

For traceability, add a `log_debug("[%X] acio device opened, path %s, baud %d", device->fd, port_path, baud);`.
icex2 commented 2021-01-16 18:07:33 +03:00 (Migrated from github.com)

Nit style: Separate control block with if by a new line.

Nit style: Separate control block with if by a new line.
icex2 commented 2021-01-16 18:08:17 +03:00 (Migrated from github.com)

Nit: Instead of malloc use xmalloc from util/mem.h. It wraps malloc + null checks.

Nit: Instead of `malloc` use `xmalloc` from `util/mem.h`. It wraps malloc + null checks.
icex2 commented 2021-01-16 18:08:35 +03:00 (Migrated from github.com)

Nit style: Separate control block with new line.

Nit style: Separate control block with new line.
icex2 commented 2021-01-16 18:14:32 +03:00 (Migrated from github.com)

Before this line, I suggest initializing the struct by zero'ing it, e.g. memset(device, 0, sizeof(struct aciodrv_device_ctx));

I think you forgot to initialize the msg_counter which was set to 1 on the old implementation. I can't remember why it was initialized with 1 but I would stick to the old implementation:
device->msg_counter = 1.

Before this line, I suggest initializing the struct by zero'ing it, e.g. `memset(device, 0, sizeof(struct aciodrv_device_ctx));` I think you forgot to initialize the `msg_counter` which was set to `1` on the old implementation. I can't remember why it was initialized with `1` but I would stick to the old implementation: `device->msg_counter = 1`.
icex2 commented 2021-01-16 18:16:28 +03:00 (Migrated from github.com)

Nit style: Separate node_id and slot_state by line break.

Nit style: Separate `node_id` and `slot_state` by line break.
icex2 commented 2021-01-16 18:17:29 +03:00 (Migrated from github.com)

Add the log_assert(device) guard to all (public) functions in this module

Add the `log_assert(device)` guard to all (public) functions in this module
icex2 commented 2021-01-16 18:18:13 +03:00 (Migrated from github.com)

Again, for traceability, add the fd to all log outputs in this module, e.g. log_warning("[%X] ...", device->fd);

Again, for traceability, add the `fd` to all log outputs in this module, e.g. `log_warning("[%X] ...", device->fd);`
icex2 commented 2021-01-16 18:20:58 +03:00 (Migrated from github.com)

Like on other modules, add log_assert(device); guard on all public functions

Like on other modules, add `log_assert(device);` guard on all public functions
icex2 commented 2021-01-16 18:21:17 +03:00 (Migrated from github.com)

Logging, add fd->device to output

Logging, add `fd->device` to output
icex2 commented 2021-01-16 18:24:41 +03:00 (Migrated from github.com)

Just an observation/thought: I was wondering what's the best way of treating "invalid" values of HANDLE since windows is also not consistent about it, e.g. using NULL or INVALID_HANDLE_VALUE. At least for our APIs/modules I think we should try our best to stick to one option. Good thing here, the return value on failure is explicitly documented.

Just an observation/thought: I was wondering what's the best way of treating "invalid" values of `HANDLE` since windows is also not consistent about it, e.g. using `NULL` or `INVALID_HANDLE_VALUE`. At least for our APIs/modules I think we should try our best to stick to one option. Good thing here, the return value on failure is explicitly documented.
icex2 commented 2021-01-16 18:26:05 +03:00 (Migrated from github.com)

For traceability, also log the fd in the message. See my other comments.

Please check other log calls in this module as well.

For traceability, also log the `fd` in the message. See my other comments. Please check other log calls in this module as well.
icex2 commented 2021-01-16 18:26:29 +03:00 (Migrated from github.com)

Nit: log_assert(bytes); guard.

Nit: `log_assert(bytes);` guard.
icex2 commented 2021-01-16 18:27:04 +03:00 (Migrated from github.com)

Nit: log_assert(bytes); guard

Nit: `log_assert(bytes);` guard
icex2 commented 2021-01-16 18:30:38 +03:00 (Migrated from github.com)

Nit style: Separate control block from other stuff with new line.

Nit style: Separate control block from other stuff with new line.
icex2 commented 2021-01-16 18:42:02 +03:00 (Migrated from github.com)

Add log_assert(device); guard to all public functions

Add `log_assert(device);` guard to all public functions
icex2 commented 2021-01-16 18:42:20 +03:00 (Migrated from github.com)

Extend log message with device->fd in module.

Extend log message with device->fd in module.
icex2 commented 2021-01-16 18:43:35 +03:00 (Migrated from github.com)

Extend log messages fd->device in module

Extend log messages fd->device in module
icex2 commented 2021-01-16 18:44:08 +03:00 (Migrated from github.com)

Nit: In the other modules, you also adapted the comments.

Nit: In the other modules, you also adapted the comments.
icex2 commented 2021-01-16 18:44:38 +03:00 (Migrated from github.com)

Add log_assert(device); guard on all public functions of module

Add `log_assert(device);` guard on all public functions of module
icex2 commented 2021-01-16 18:46:00 +03:00 (Migrated from github.com)

Nit style: Empty line before control block

Nit style: Empty line before control block
icex2 commented 2021-01-16 18:47:17 +03:00 (Migrated from github.com)

Nit style: Empty line before control block

Nit style: Empty line before control block
icex2 commented 2021-01-16 18:47:49 +03:00 (Migrated from github.com)

Nit style: empty line before control block

Nit style: empty line before control block
icex2 commented 2021-01-16 18:48:06 +03:00 (Migrated from github.com)

Nit style: empty line before control block

Nit style: empty line before control block
icex2 commented 2021-01-17 00:12:06 +03:00 (Migrated from github.com)

In GitLab by @xyen on Jan 16, 2021, 22:12

Commented on src/main/aciodrv/port.h line 17

HANDLE is a void*, I'd rather keep to NULL in this case.

In GitLab by @xyen on Jan 16, 2021, 22:12 Commented on [src/main/aciodrv/port.h line 17](https://github.com/djhackersdev/bemanitools/compare/f945a2d3e5c64c2950edd91c06b7fa9f425aa8dc..6f490d440c420ca66596e995b502f535d8371ac9#diff-3ceaad487c3d210c60e1790417548daeR17) `HANDLE` is a void*, I'd rather keep to NULL in this case.
icex2 commented 2021-01-20 07:45:34 +03:00 (Migrated from github.com)

In GitLab by @xyen on Jan 20, 2021, 05:45

Commented on src/main/aciodrv/device.c line 338

I've added it to the section that say beginning send/recv, I don't think it makes sense to add it to the other ones (as they'd be wrapped / preceded by these 2 messages).

In GitLab by @xyen on Jan 20, 2021, 05:45 Commented on [src/main/aciodrv/device.c line 338](https://github.com/djhackersdev/bemanitools/compare/f945a2d3e5c64c2950edd91c06b7fa9f425aa8dc..241f0f65ec109317ee987a7461b8c4c55fb6545f#diff-1c1a2ad8deb60fa4bb473a3e4f9e4732L338) I've added it to the section that say beginning send/recv, I don't think it makes sense to add it to the other ones (as they'd be wrapped / preceded by these 2 messages).
icex2 commented 2021-01-20 07:47:42 +03:00 (Migrated from github.com)

In GitLab by @xyen on Jan 20, 2021, 05:47

Commented on src/main/aciodrv/device.c line 357

Sure for the logging in close. The other functions didn't have asserts to begin though, and I'm wary of adding them to code in the critical IO path.

In GitLab by @xyen on Jan 20, 2021, 05:47 Commented on [src/main/aciodrv/device.c line 357](https://github.com/djhackersdev/bemanitools/compare/f945a2d3e5c64c2950edd91c06b7fa9f425aa8dc..6f490d440c420ca66596e995b502f535d8371ac9#diff-1c1a2ad8deb60fa4bb473a3e4f9e4732L357) Sure for the logging in close. The other functions didn't have asserts to begin though, and I'm wary of adding them to code in the critical IO path.
icex2 commented 2021-01-20 07:50:17 +03:00 (Migrated from github.com)

In GitLab by @xyen on Jan 20, 2021, 05:50

Commented on src/main/aciodrv/device.c line 334

this is already done in port.c

In GitLab by @xyen on Jan 20, 2021, 05:50 Commented on [src/main/aciodrv/device.c line 334](https://github.com/djhackersdev/bemanitools/compare/f945a2d3e5c64c2950edd91c06b7fa9f425aa8dc..6f490d440c420ca66596e995b502f535d8371ac9#diff-1c1a2ad8deb60fa4bb473a3e4f9e4732R334) this is already done in port.c
icex2 commented 2021-01-20 07:56:33 +03:00 (Migrated from github.com)

In GitLab by @xyen on Jan 20, 2021, 05:56

Commented on src/main/aciodrv/icca.c line 20

device is forward declared, no namespace outside of device.c have access to it.

In GitLab by @xyen on Jan 20, 2021, 05:56 Commented on [src/main/aciodrv/icca.c line 20](https://github.com/djhackersdev/bemanitools/compare/f945a2d3e5c64c2950edd91c06b7fa9f425aa8dc..6f490d440c420ca66596e995b502f535d8371ac9#diff-771622e1b109b2c63ad64a64f7f8034cL20) device is forward declared, no namespace outside of `device.c` have access to it.
icex2 commented 2021-01-20 07:57:34 +03:00 (Migrated from github.com)

In GitLab by @xyen on Jan 20, 2021, 05:57

Commented on src/main/aciodrv/kfca.c line 60

see before

In GitLab by @xyen on Jan 20, 2021, 05:57 Commented on [src/main/aciodrv/kfca.c line 60](https://github.com/djhackersdev/bemanitools/compare/f945a2d3e5c64c2950edd91c06b7fa9f425aa8dc..6f490d440c420ca66596e995b502f535d8371ac9#diff-8d31ee7b610b97d9222b2c92c080750cL60) see before
icex2 commented 2021-01-20 08:08:39 +03:00 (Migrated from github.com)

In GitLab by @xyen on Jan 20, 2021, 06:08

Because it's impossible to extend the fd log messages outside of port/device, I've elected instead to make sure that every possible aciodrv_send_and_recv failure path will make sure to log the fd there instead.

In GitLab by @xyen on Jan 20, 2021, 06:08 Because it's impossible to extend the fd log messages outside of port/device, I've elected instead to make sure that every possible `aciodrv_send_and_recv` failure path will make sure to log the fd there instead.
icex2 commented 2021-01-20 08:08:40 +03:00 (Migrated from github.com)

In GitLab by @xyen on Jan 20, 2021, 06:08

Commented on src/main/bio2drv/bi2a-iidx.c line 28

cannot

In GitLab by @xyen on Jan 20, 2021, 06:08 Commented on [src/main/bio2drv/bi2a-iidx.c line 28](https://github.com/djhackersdev/bemanitools/compare/f945a2d3e5c64c2950edd91c06b7fa9f425aa8dc..6f490d440c420ca66596e995b502f535d8371ac9#diff-84c63f8bc3347c0c5d39083f095891a9L28) cannot
icex2 commented 2021-01-20 08:08:40 +03:00 (Migrated from github.com)

In GitLab by @xyen on Jan 20, 2021, 06:08

Commented on src/main/bio2drv/bi2a-sdvx.c line 30

cannot

In GitLab by @xyen on Jan 20, 2021, 06:08 Commented on [src/main/bio2drv/bi2a-sdvx.c line 30](https://github.com/djhackersdev/bemanitools/compare/f945a2d3e5c64c2950edd91c06b7fa9f425aa8dc..6f490d440c420ca66596e995b502f535d8371ac9#diff-fe2774e5ce16699a9545ddd85021f03fL30) cannot
icex2 commented 2021-01-20 08:10:54 +03:00 (Migrated from github.com)

In GitLab by @xyen on Jan 20, 2021, 06:10

Commented on src/main/aciodrv/device.c line 17

changed this line in version 4 of the diff

In GitLab by @xyen on Jan 20, 2021, 06:10 Commented on [src/main/aciodrv/device.c line 17](https://github.com/djhackersdev/bemanitools/compare/f945a2d3e5c64c2950edd91c06b7fa9f425aa8dc..841d34065da42cd32173274ae9e1f3a3c620587a#diff-1c1a2ad8deb60fa4bb473a3e4f9e4732R17) changed this line in [version 4 of the diff](/djhackers/bemanitools/-/merge_requests/77/diffs?diff_id=1450&start_sha=841d34065da42cd32173274ae9e1f3a3c620587a#c04cec926c4bc2a62496efc8522ee127583ae23a_17_19)
icex2 commented 2021-01-20 08:10:55 +03:00 (Migrated from github.com)

In GitLab by @xyen on Jan 20, 2021, 06:10

Commented on src/main/aciodrv/device.c line 346

changed this line in version 4 of the diff

In GitLab by @xyen on Jan 20, 2021, 06:10 Commented on [src/main/aciodrv/device.c line 346](https://github.com/djhackersdev/bemanitools/compare/f945a2d3e5c64c2950edd91c06b7fa9f425aa8dc..841d34065da42cd32173274ae9e1f3a3c620587a#diff-1c1a2ad8deb60fa4bb473a3e4f9e4732L346) changed this line in [version 4 of the diff](/djhackers/bemanitools/-/merge_requests/77/diffs?diff_id=1450&start_sha=841d34065da42cd32173274ae9e1f3a3c620587a#c04cec926c4bc2a62496efc8522ee127583ae23a_371_380)
icex2 commented 2021-01-20 08:10:55 +03:00 (Migrated from github.com)

In GitLab by @xyen on Jan 20, 2021, 06:10

Commented on src/main/aciodrv/device.c line 340

changed this line in version 4 of the diff

In GitLab by @xyen on Jan 20, 2021, 06:10 Commented on [src/main/aciodrv/device.c line 340](https://github.com/djhackersdev/bemanitools/compare/f945a2d3e5c64c2950edd91c06b7fa9f425aa8dc..841d34065da42cd32173274ae9e1f3a3c620587a#diff-1c1a2ad8deb60fa4bb473a3e4f9e4732R340) changed this line in [version 4 of the diff](/djhackers/bemanitools/-/merge_requests/77/diffs?diff_id=1450&start_sha=841d34065da42cd32173274ae9e1f3a3c620587a#c04cec926c4bc2a62496efc8522ee127583ae23a_340_348)
icex2 commented 2021-01-20 08:10:55 +03:00 (Migrated from github.com)

In GitLab by @xyen on Jan 20, 2021, 06:10

Commented on src/main/aciodrv/icca.h line 33

changed this line in version 4 of the diff

In GitLab by @xyen on Jan 20, 2021, 06:10 Commented on [src/main/aciodrv/icca.h line 33](https://github.com/djhackersdev/bemanitools/compare/f945a2d3e5c64c2950edd91c06b7fa9f425aa8dc..841d34065da42cd32173274ae9e1f3a3c620587a#diff-b8e12cf030d961efacf87abea29950a8R33) changed this line in [version 4 of the diff](/djhackers/bemanitools/-/merge_requests/77/diffs?diff_id=1450&start_sha=841d34065da42cd32173274ae9e1f3a3c620587a#da5d3ceef9e27735b48d6518c7c15a4b7d749b33_33_33)
icex2 commented 2021-01-20 08:10:56 +03:00 (Migrated from github.com)

In GitLab by @xyen on Jan 20, 2021, 06:10

Commented on src/main/aciodrv/port.c line 103

changed this line in version 4 of the diff

In GitLab by @xyen on Jan 20, 2021, 06:10 Commented on [src/main/aciodrv/port.c line 103](https://github.com/djhackersdev/bemanitools/compare/f945a2d3e5c64c2950edd91c06b7fa9f425aa8dc..841d34065da42cd32173274ae9e1f3a3c620587a#diff-5243a13f56e2aa52ae1f6cead81374f2R103) changed this line in [version 4 of the diff](/djhackers/bemanitools/-/merge_requests/77/diffs?diff_id=1450&start_sha=841d34065da42cd32173274ae9e1f3a3c620587a#3f8da9d4cc219dcbec88b974ab4b79ef662a320a_103_103)
icex2 commented 2021-01-20 08:10:57 +03:00 (Migrated from github.com)

In GitLab by @xyen on Jan 20, 2021, 06:10

added 1 commit

Compare with previous version

In GitLab by @xyen on Jan 20, 2021, 06:10 added 1 commit <ul><li>6f490d44 - aciodrv: address review</li></ul> [Compare with previous version](/djhackers/bemanitools/-/merge_requests/77/diffs?diff_id=1450&start_sha=841d34065da42cd32173274ae9e1f3a3c620587a)
icex2 commented 2021-01-20 20:54:04 +03:00 (Migrated from github.com)

In GitLab by @xyen on Jan 20, 2021, 18:54

resolved all threads

In GitLab by @xyen on Jan 20, 2021, 18:54 resolved all threads
icex2 commented 2021-01-20 23:18:58 +03:00 (Migrated from github.com)

I would say it does make sense if you have two separate ACIO devices running at the same time and just want to do a grep on the file output for a single device.

I would say it does make sense if you have two separate ACIO devices running at the same time and just want to do a grep on the file output for a single device.
icex2 commented 2021-01-20 23:26:44 +03:00 (Migrated from github.com)

In GitLab by @xyen on Jan 20, 2021, 21:26

Commented on src/main/aciodrv/device.c line 338

ah, my comment is no longer valid, I ended up adding it to all the log messages in this module.

In GitLab by @xyen on Jan 20, 2021, 21:26 Commented on [src/main/aciodrv/device.c line 338](https://github.com/djhackersdev/bemanitools/compare/f945a2d3e5c64c2950edd91c06b7fa9f425aa8dc..241f0f65ec109317ee987a7461b8c4c55fb6545f#diff-1c1a2ad8deb60fa4bb473a3e4f9e4732L338) ah, my comment is no longer valid, I ended up adding it to all the log messages in this module.
icex2 commented 2021-01-20 23:26:44 +03:00 (Migrated from github.com)

In GitLab by @xyen on Jan 20, 2021, 21:26

resolved all threads

In GitLab by @xyen on Jan 20, 2021, 21:26 resolved all threads
icex2 commented 2021-01-20 23:28:29 +03:00 (Migrated from github.com)

approved this merge request

approved this merge request
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Max/djhackersdev_bemanitools#178