From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 07/10] mci: add support for discarding write blocks
Date: Tue, 30 Jul 2024 13:17:07 +0200 [thread overview]
Message-ID: <7f0e6122-2a6f-4d88-88f6-17abebc4595a@pengutronix.de> (raw)
In-Reply-To: <Zqi6zHop6xz7jMvo@pengutronix.de>
On 30.07.24 12:05, Sascha Hauer wrote:
> On Tue, Jul 30, 2024 at 09:19:26AM +0200, Ahmad Fatoum wrote:
>> + __be32 *ssr;
>> + int err;
>> + unsigned int au, eo, et, es;
>> +
>> + if (!IS_ENABLED(CONFIG_MCI_ERASE))
>> + return -ENOSYS;
>
> I think we settled on using -EOPNOTSUPP in this case.
I like -ENOSYS, because it indicates that supper is merely missing instead of not
being available in the first place.
>> + if (mci->can_trim) {
>> + arg = MMC_TRIM_ARG;
>> + } else {
>> + /* We don't use discard, as it doesn't guarantee a fixed value */
>> + arg = MMC_ERASE_ARG;
>> + blkcnt = mmc_align_erase_size(mci, &from, &to, blkcnt);
>> + }
>> +
>> + if (blkcnt == 0)
>> + return 0;
>> +
>> + if (to <= from)
>> + return -EINVAL;
>
> When mmc_align_erase_size() is not called then we cannot arrive here
> as we already returned in the if (blkcnt == 0) check above.
> When mmc_align_erase_size() is called and this test triggers then it
> only reveals a bug in mmc_align_erase_size().
>
> I think this test should go away.
>> + while (i < blkcnt) {
>> + sector_t blk_r;
>> +
>> + /* TODO: While it's possible to clear many erase groups at once
>> + * and it greatly improves throughput, drivers need adjustment:
>> + *
>> + * Many drivers hardcode a maximal wait time before aborting
>> + * the wait for R1b and returning -ETIMEDOUT. With long
>> + * erases/trims, we are bound to run into this timeout, so for now
>> + * we just split into suifficiently small erases that are unlikely
>> + * to trigger the time.
>> + *
>> + * What Linux does and what we should be doing in barebox is:
>> + *
>> + * - add a struct mci_cmd::busy_timeout member that drivers should
>> + * use instead of hardcoding their own timeout delay. The busy
>> + * timeout length can be calculated by the MCI core after
>> + * consulting the appropriate CSD/EXT_CSD/SSR registers.
>> + *
>> + * - add a struct mci_host::max_busy_timeout member, where drivers
>> + * can indicate the maximum timeout they are able to support.
>> + * The MCI core will never set a busy_timeout that exceeds this
>> + * value.
>> + *
>> + * Example Samsung eMMC 8GTF4:
>> + *
>> + * time erase /dev/mmc2.part_of_512m # 1024 trims
>> + * time: 2849ms
>> + *
>> + * time erase /dev/mmc2.part_of_512m # single trim
>> + * time: 56ms
>> + */
>> +
>> + if (IS_SD(mci) && mci->ssr.au) {
>> + blk_r = ((blkcnt - i) > mci->ssr.au) ?
>> + mci->ssr.au : (blkcnt - i);
>> + } else {
>> + blk_r = ((blkcnt - i) > mci->erase_grp_size) ?
>> + mci->erase_grp_size : (blkcnt - i);
>> + }
>> +
>> + rc = mci_block_erase(mci, from, to, arg);
>
> You say you split up the whole erase into sufficiently small erases, but
> 'from' and 'to' are never changed in this loop and you seem to erase
> the whole area multiple times.
Ouch. Will revisit.
Thanks,
Ahmad
>
>> + if (rc)
>> + break;
>> +
>> + /* Waiting for the ready status */
>> + rc = mci_poll_until_ready(mci, 1000 /* ms */);
>> + if (rc)
>> + break;
>> +
>> + i += blk_r;
>> + }
>> +
>> + return i == blkcnt ? 0 : rc;
>> +}
>
> Sascha
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2024-07-30 11:19 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-30 7:19 [PATCH 00/10] mmc: add SD/eMMC erase support Ahmad Fatoum
2024-07-30 7:19 ` [PATCH 01/10] fs: give erase() a new erase_type parameter Ahmad Fatoum
2024-07-30 8:31 ` Sascha Hauer
2024-07-30 8:32 ` Ahmad Fatoum
2024-07-30 7:19 ` [PATCH 02/10] block: factor out chunk_flush helper Ahmad Fatoum
2024-07-30 7:19 ` [PATCH 03/10] block: allow block devices to implement the cdev erase operation Ahmad Fatoum
2024-07-30 8:55 ` Sascha Hauer
2024-07-30 11:10 ` Ahmad Fatoum
2024-07-30 11:21 ` Sascha Hauer
2024-07-30 7:19 ` [PATCH 04/10] mci: turn bool members into bitfield in struct mci Ahmad Fatoum
2024-07-30 9:06 ` Sascha Hauer
2024-07-30 11:10 ` Ahmad Fatoum
2024-07-30 7:19 ` [PATCH 05/10] mci: describe more command structure in mci.h Ahmad Fatoum
2024-07-30 9:25 ` Yann Sionneau
2024-07-30 11:07 ` Ahmad Fatoum
2024-07-30 7:19 ` [PATCH 06/10] mci: core: use CONFIG_MCI_WRITE, not CONFIG_BLOCK_WRITE Ahmad Fatoum
2024-07-30 9:18 ` Sascha Hauer
2024-07-30 11:08 ` Ahmad Fatoum
2024-07-31 7:19 ` Ahmad Fatoum
2024-07-30 7:19 ` [PATCH 07/10] mci: add support for discarding write blocks Ahmad Fatoum
2024-07-30 9:23 ` Yann Sionneau
2024-07-30 11:14 ` Ahmad Fatoum
2024-07-30 10:05 ` Sascha Hauer
2024-07-30 11:17 ` Ahmad Fatoum [this message]
2024-07-30 7:19 ` [PATCH 08/10] commands: sync: add new command to flush cached writes Ahmad Fatoum
2024-07-30 10:08 ` Sascha Hauer
2024-07-30 7:19 ` [PATCH 09/10] mci: core: remove reference to SD Card from common mci_card_probe Ahmad Fatoum
2024-07-30 10:09 ` Sascha Hauer
2024-07-30 7:19 ` [PATCH 10/10] commands: blkstats: add command to print block device statistics Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7f0e6122-2a6f-4d88-88f6-17abebc4595a@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox