* MTD access problem
@ 2002-05-28 19:18 Xiaogeng (Shawn) Jin
2002-11-28 21:39 ` Wolfgang Denk
0 siblings, 1 reply; 2+ messages in thread
From: Xiaogeng (Shawn) Jin @ 2002-05-28 19:18 UTC (permalink / raw)
To: linux-mtd, Wolfgang Denk
I'm experiencing a strange mtd access problem when two threads try to
access two different mtd devices which are in the same chip (using CS0).
This happens as follows.
1. Thread A calls get_mtd_device() to an mtd handle (e.g. mtd6), calls
erase() to erase one sector (128K byte), and tries to write some data
into this sector, then calls put_mtd_device() to return the handle.
2. At the same time, thread B tries the same action on another mtd
device (e.g. mtd5).
3. The strange thing happens. The write action takes long time (10
minutes, sometimes even longer) to finish.
I'm not sure this problem is usual or not. My flash is AMD29LV642D. The
mtd code is from DENX distribution 2.4.4-2002-08-09. It may not be the
latest one from CVS.
Wolfgang, is the mtd code from your distribution the same as the mtd cvs
from infradead.org?
I hacked into the mtd source code "mtdcore.c" and found a *temporary*
solution to my problem. I added the following two functions. Basically,
I intentionally delay the release of mtd_table_mutex until a user calls
rs_put_mtd_device() to release an mtd handle. When rs_get_mtd_device()
is called, only one can get permission to access an mtd device, thus it
prevents the above problem from taking place. Since my threads do not
write to mtd devices very frequently, I can tolerate such inefficiency.
Obviously, this is not a good fix, or may be a wrong one. Any
suggestions? Thank you very much.
Happy Thanksgiving!
- Shawn.
struct mtd_info *rs_get_mtd_device(struct mtd_info *mtd, int num)
{
struct mtd_info *ret = NULL;
int i;
down(&mtd_table_mutex);
if (num == -1) {
for (i=0; i< MAX_MTD_DEVICES; i++)
if (mtd_table[i] == mtd)
ret = mtd_table[i];
} else if (num < MAX_MTD_DEVICES) {
ret = mtd_table[num];
if (mtd && mtd != ret)
ret = NULL;
}
if (ret && ret->module && !try_inc_mod_count(ret->module)) {
up(&mtd_table_mutex);
return NULL;
}
return ret;
}
void rs_put_mtd_device(struct mtd_info *mtd)
{
up(&mtd_table_mutex);
if (mtd->module)
__MOD_DEC_USE_COUNT(mtd->module);
}
EXPORT_SYMBOL(rs_get_mtd_device);
EXPORT_SYMBOL(rs_put_mtd_device);
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: MTD access problem
2002-05-28 19:18 MTD access problem Xiaogeng (Shawn) Jin
@ 2002-11-28 21:39 ` Wolfgang Denk
0 siblings, 0 replies; 2+ messages in thread
From: Wolfgang Denk @ 2002-11-28 21:39 UTC (permalink / raw)
To: Xiaogeng (Shawn) Jin; +Cc: linux-mtd
In message <3CF3D7FB.5020500@redswitch.com> you wrote:
>
> I'm not sure this problem is usual or not. My flash is AMD29LV642D. The
> mtd code is from DENX distribution 2.4.4-2002-08-09. It may not be the
> latest one from CVS.
It is definitely not "the latest".
> Wolfgang, is the mtd code from your distribution the same as the mtd cvs
> from infradead.org?
As you can see from a short look at our CVS server it is based on a
CVS snapshot taken 2001-10-09.
Best regards,
Wolfgang Denk
--
Software Engineering: Embedded and Realtime Systems, Embedded Linux
Phone: (+49)-8142-4596-87 Fax: (+49)-8142-4596-88 Email: wd@denx.de
Quantum Mechanics is God's version of "Trust me."
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-11-28 21:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-05-28 19:18 MTD access problem Xiaogeng (Shawn) Jin
2002-11-28 21:39 ` Wolfgang Denk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox