Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sival, i2c] chip_sw_i2c_speed test #20436

Merged
merged 9 commits into from
Jan 24, 2024
Merged

Conversation

engdoreis
Copy link
Contributor

This PR:

  • Optimize the existing i2c DIF and testutils for speed.
  • Refactor the pmod:fram test to run with all the i2c instances.
  • Add a throughput step to the pmod:fram test.

Fix #19836

@engdoreis engdoreis requested a review from a team as a code owner November 22, 2023 14:48
@engdoreis engdoreis requested review from jadephilipoom and a-will and removed request for a team November 22, 2023 14:48
@engdoreis engdoreis marked this pull request as draft November 22, 2023 14:57
Comment on lines +579 to +580
dif_result_t dif_i2c_read_bytes(const dif_i2c_t *i2c, size_t size,
uint8_t *buffer);
Copy link
Contributor

@a-will a-will Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue that this belongs in an i2c_testutils, not the DIFs. It imposes blocking semantics, where it probably ought to allow for some sort of timeout + bytes actually read, which then might require other IPs for measuring. This is target mode, so our device here doesn't have control of timing or whether a transaction will ever complete.

@engdoreis engdoreis marked this pull request as ready for review January 18, 2024 10:46
@engdoreis engdoreis requested review from pamaury and jwnrt and removed request for jadephilipoom January 18, 2024 10:46
Copy link
Contributor

@jwnrt jwnrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look correct to me, thanks @engdoreis. I haven't checked the tests in depth, but if they pass then that's good enough for me.

I agree with @a-will that those blocking difs might be better off in testutils with a timeout.

sw/device/lib/dif/dif_i2c.c Outdated Show resolved Hide resolved
sw/device/lib/testing/i2c_testutils.c Show resolved Hide resolved
sw/device/lib/testing/i2c_testutils.c Outdated Show resolved Hide resolved
@engdoreis engdoreis force-pushed the sival_i2c_speed branch 3 times, most recently from a0629e9 to ce7dcca Compare January 18, 2024 16:34
@engdoreis
Copy link
Contributor Author

engdoreis commented Jan 18, 2024

I agree with @a-will that those blocking difs might be better off in testutils with a timeout.

For reference, the dif_spi_host also contains blocking routines for feeding the FIFO and checking status registers:

while (misalignment32_of(ptr) && len > 0) {
tx_fifo_write8(spi_host, ptr);
ptr += 1;
len -= 1;
}
// Write complete 32-bit words to the fifo.
while (len > 3) {
tx_fifo_write32(spi_host, ptr);
ptr += 4;
len -= 4;
}
// Clean up any leftover bytes.
while (len > 0) {
tx_fifo_write8(spi_host, ptr);
ptr += 1;
len -= 1;
}

Copy link
Contributor

@pamaury pamaury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know the i2c block really well but overall this looks good to me.

@engdoreis engdoreis force-pushed the sival_i2c_speed branch 3 times, most recently from 11da589 to d27d10b Compare January 23, 2024 18:08
@engdoreis engdoreis merged commit 9b5b4c6 into lowRISC:master Jan 24, 2024
32 checks passed
@a-will
Copy link
Contributor

a-will commented Jan 24, 2024

I agree with @a-will that those blocking difs might be better off in testutils with a timeout.

For reference, the dif_spi_host also contains blocking routines for feeding the FIFO and checking status registers:

while (misalignment32_of(ptr) && len > 0) {
tx_fifo_write8(spi_host, ptr);
ptr += 1;
len -= 1;
}
// Write complete 32-bit words to the fifo.
while (len > 3) {
tx_fifo_write32(spi_host, ptr);
ptr += 4;
len -= 4;
}
// Clean up any leftover bytes.
while (len > 0) {
tx_fifo_write8(spi_host, ptr);
ptr += 1;
len -= 1;
}

FYI, that is merely a past mistake that should not be used as a reference. That function also should not have been in the DIFs.

However, there is a significant difference between I2C in target mode and spi_host, as I pointed out in the last line: Our I2C device here doesn't have control of timing or whether a transaction will ever complete. By contrast, spi_host is guaranteed to make forward progress to its end state. That is why the i2c functions need to be in testutils and make effective use of timeouts.

@engdoreis
Copy link
Contributor Author

engdoreis commented Jan 24, 2024

Our I2C device here doesn't have control of timing or whether a transaction will ever complete.

That makes sense, I'll move the functions to the testutils when working on i2c_dev tests.

@engdoreis engdoreis added the CherryPick:earlgrey_es_sival This PR should be cherry-picked to earlgrey_es_sival label Feb 15, 2024
Copy link

Successfully created backport PR for earlgrey_es_sival:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CherryPick:earlgrey_es_sival This PR should be cherry-picked to earlgrey_es_sival
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[chip-test] chip_sw_i2c_speed
4 participants