3

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)など) を実装できます。

だから私の質問は:

  1. 変数「volatile」を宣言して、可視性とインターリーブなしの意味で読み取りと書き込みの原子性を達成するだけで十分ですか?

  2. 1に対する答えが「いいえ」の場合、そのような原子性はどのように達成されますか?

  3. Linux PowerPC アトミック実装における「%U0%X0」の意味は何ですか?

4

2 に答える 2

1

There are idiosyncrasies in the GCC inline assembly syntax.

in the line,

__asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));

the m is an output operand and the r is an input operand. The %1 and %0 refer to the argument order (0->m, 1->r)

the stw assembly instruction takes 2 arguments and the %U0%X0 are constraints on the arguments. These constraints are to force GCC to analyze the arguments and make sure you dont do something stupid. As it turns out, `U' is powerpc-specific (I'm used to the X64 constraint set :). The full list of constraints can be found in :

http://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html#Machine-Constraints

于 2011-08-25T05:22:39.747 に答える
0

質問 1 と 2 には答えることができましたが、3 には答えられませんでした。

  1. いいえ、それだけでは十分ではありません。
  2. メモリバリアは引き続き必要です。__lwsync() に組み込まれている XLC を使用しました。これにより、プロセッサによる並べ替えが防止され、変更が他のプロセッサに公開されます。
于 2011-07-27T17:15:03.327 に答える