I'm porting a kernel extentsion to 32/64 bit AIX on multi-processor PowerPC, written in C. I don't need more than atomic read operation and atomic write operations (I have no use for fetch-and-add, compare-and-swap etc.) Just to clarify: to me, "atomicity" means not only "no interleaving", but also "visibility across multiple cores". The operations operate on pointers, so operations on 'int' variables are useless to me.
If I declare the variable "volatile", the C standard says the variable can be modified by unknown factors and is therefore not subject to optimizations.
From what I read, it seems that regular reads and writes are supposed to be non-interleaved, and the linux kernel souces seem to agree. it says:
__asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
stw
おそらくアトミックである「ストアワード」ですが、「%U0%X0」が何を意味するのかわかりません。このアセンブリ命令がどのように可視性を課すのか理解できません。カーネル拡張機能をコンパイルすると、必要な割り当てに「std」が使用されますが、読んだところによると、64ビットマシンでもアトミックである必要があります。PowerPC とその命令セットの詳細についてはほとんど理解していませんが、コンパイルされたファイルのアセンブリ リストに、メモリ バリア命令 (「sync」または「eieio」) が見つかりませんでした。
カーネルは fetch_and_addlp() サービスを提供し、これを使用してアトミック読み取り (v = fetch_and_addlp(&x, 0)
など) を実装できます。
だから私の質問は:
変数「volatile」を宣言して、可視性とインターリーブなしの意味で読み取りと書き込みの原子性を達成するだけで十分ですか?
1に対する答えが「いいえ」の場合、そのような原子性はどのように達成されますか?
Linux PowerPC アトミック実装における「%U0%X0」の意味は何ですか?