From: EXT Nicolas Morey-Chaisemartin [mailto:nmo...@kalray.eu] Sent: Thursday, November 05, 2015 6:23 PM To: Savolainen, Petri (Nokia - FI/Espoo); Bill Fischofer Cc: LNG ODP Mailman List Subject: Re: [lng-odp] [API-NEXT PATCH] api: sync: update spec and add odp_sync_loads
On 11/05/2015 04:54 PM, Savolainen, Petri (Nokia - FI/Espoo) wrote: Majority of platforms are cache coherent, for a non-coherent platform you’d need to define some additional API calls. This is documenting the current assumption that application does this … // data in shared memory int foo; Thread A Thread B ev = schedule(); msg = event_to_message(ev); if (msg == UPDATE_FOO) { foo++; msg = FOO_UPDATED; queue_enq(msg); } ev = schedule(); msg = event_to_message(ev); if (msg == FOO_UPDATED) { printf(“foo is now %\n”, foo); } … intead of this … Thread A Thread B ev = schedule(); msg = event_to_message(ev); if (msg == UPDATE_FOO) { // Make sure that load of “foo” is not moved before schedule() odp_sync_loads(); foo++; // Make sure that store of “foo” is not moved after queue_enq() odp_sync_stores(); msg = FOO_UPDATED; queue_enq(msg); } ev = schedule(); msg = event_to_message(ev); if (msg == FOO_UPDATED) { // Make sure that load of “foo” is not moved before schedule() odp_sync_loads(); printf(“foo is now %\n”, foo); } As you can see it would a lot of waste if application must always sync for stores and loads explicitly. I see your point. I re-read carefully the documentation and maybe we can work around it. The sync_stores explicitly states that all store operations are globally visible. So cache needs to be flushed. The load part only states that previous memory operations are complete, and cannot be reordered around it. It does not explicitly states that the cache needs to be up-to-date. We internally use "read memory barrier" internally as DINVAL + FENCE but it is not necessary the case. If my understanding of the function fits with yours, I'm good with this patches. If not, we need to discuss things some more. Nicolas The above highlights how it should *not* be used (== not needed with ready-made ODP sync mechanisms). It’s intended to be used with non-ODP sync mechanisms like the one under. Store and load syncs are usually a pair (sync_stores -> sync_loads). -Petri // data and flag in shared memory volatile int flag = 0; int foo = 0; Thread A Thread B foo = 0xbeef; // Make sure that store // of "foo" is visible before // store of "flag" odp_sync_stores(); flag = 1; while (flag == 0) spin_and_wait(); // Make sure that load of // "foo" does not happen before // we see the flag changing odp_sync_loads(); printf(“foo is now %\n”, foo); _______________________________________________ lng-odp mailing list lng-odp@lists.linaro.org https://lists.linaro.org/mailman/listinfo/lng-odp