-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getAffinity: incompatible types: java.util.BitSet cannot be converted to long #47
Comments
This method was changed to support systems with more than 64 cpus. Is this
an example from the documentation? If so we can correct it.
On 15 Sep. 2017 07:38, "Xiaofeng Wu" <[email protected]> wrote:
I try to set affinity to one thread, however,
If you want to get/set the affinity directly you can do
long currentAffinity = AffinitySupport.getAffinity();
AffinitySupport.setAffinity(1L << 5); // lock to CPU 5.
I get some errors about data type.
Error:(21, 52) java: incompatible types: java.util.BitSet cannot be
converted to long
Error:(22, 17) java: no suitable method found for setAffinity(long)
method net.openhft.affinity.Affinity.setAffinity(java.util.BitSet)
is not applicable
(argument mismatch; long cannot be converted to java.util.BitSet)
method net.openhft.affinity.Affinity.setAffinity(int) is not applicable
(argument mismatch; possible lossy conversion from long to int)
The code
package net.openhft.affinity;import static
net.openhft.affinity.AffinityStrategies.*;//import static
net.openhft.affinity.Affinity.*;/** * @author peter.lawrey */public
final class AffinityLockBindMainTest {
private AffinityLockBindMainTest() {
throw new InstantiationError( "Must not instantiate this class" );
}
public static void main(String... args) throws InterruptedException {
AffinityLock al = AffinityLock.acquireLock();
int threadId = AffinitySupport.getThreadId();
System.out.println("threadId of main "+ threadId);
int cpuId = Affinity.getCpu();
System.out.println("cpuId of main: " + cpuId);
long currentAffinity = Affinity.getAffinity();
Affinity.setAffinity(1L << 5); // lock to CPU 5.
try {
// find a cpu on a different socket, otherwise a different core.
AffinityLock readerLock = al.acquireLock(DIFFERENT_SOCKET,
DIFFERENT_CORE);
new Thread(new SleepRunnable(readerLock, false), "reader").start();
// find a cpu on the same core, or the same socket, or any free cpu.
//AffinityLock writerLock =
readerLock.acquireLock(SAME_CORE, SAME_SOCKET, ANY);
//new Thread(new SleepRunnable(writerLock, false),
"writer").start();
Thread.sleep(200);
} finally {
al.release();
}
// allocate a whole core to the engine so it doesn't have to
compete for resources.
//al = AffinityLock.acquireCore(false);
//new Thread(new SleepRunnable(al, true), "engine").start();
Thread.sleep(200);
System.out.println("\nThe assignment of CPUs is\n" +
AffinityLock.dumpLocks());
}
static class SleepRunnable implements Runnable {
private final AffinityLock affinityLock;
private final boolean wholeCore;
SleepRunnable(AffinityLock affinityLock, boolean wholeCore) {
this.affinityLock = affinityLock;
this.wholeCore = wholeCore;
}
public void run() {
affinityLock.bind(wholeCore);
int threadId = AffinitySupport.getThreadId();
System.out.println("threadId of one SleepRunnable "+ threadId);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} finally {
affinityLock.release();
}
}
}
}
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#47>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABBU8U-t1rSozp8E5as2ejDqRuagiZplks5sihtdgaJpZM4PYjEZ>
.
|
Dear Peter, Yes, I follow the tutorial in The file path of the test Java program is in The purpose of my modification is that I want to bind But I don't know how to do it right now. I am not sure how to implement it since I haven't fully understand funciton usage like What I want to do is that, for example, I would like to do a very simple single thread implementation.
import java.util.ArrayDeque;
public class Runner {
public static void main(String[] args) throws InterruptedException {
ArrayDeque<byte[]> deque = new ArrayDeque<byte[]>(); // define a deque
int objectSize = 1024;
for(int i = 0; i < 5000; i++){
for(int j = 0; j < 100; j++){
deque.addLast(new byte[objectSize]); // put something into it
}
for(int j = 0; j < 10; j++){
deque.removeLast(); // get something out
}
}
}
} So I try to comment
long currentAffinity = AffinitySupport.getAffinity(); // (1)
AffinitySupport.setAffinity(1L << 5); // lock to CPU 5.// (2) And I find that Appendix of Code : package net.openhft.affinity;
import java.util.BitSet;
import static net.openhft.affinity.AffinityStrategies.*;
//import static net.openhft.affinity.Affinity.*;
/**
* @author peter.lawrey
*/
public final class AffinityLockBindMainTest {
private AffinityLockBindMainTest() {
throw new InstantiationError( "Must not instantiate this class" );
}
public static void main(String... args) throws InterruptedException {
AffinityLock al = AffinityLock.acquireLock();
int threadId = AffinitySupport.getThreadId();
System.out.println("threadId of main "+ threadId);
int cpuId = Affinity.getCpu();
System.out.println("cpuId of main: " + cpuId);
// current cpu bitmap
BitSet currentAffinity = Affinity.getAffinity();
// print the bitmap
StringBuilder s = new StringBuilder();
for( int i = 0; i < currentAffinity.length(); i++ )
{
s.append( currentAffinity.get( i ) == true ? 1: 0 );
}
System.out.println( s );
//Affinity.setAffinity( 1L << 5 ); // lock to CPU 5.
try {
// find a cpu on a different socket, otherwise a different core.
AffinityLock readerLock = al.acquireLock(DIFFERENT_SOCKET, DIFFERENT_CORE);
new Thread(new SleepRunnable(readerLock, false), "reader").start();
// find a cpu on the same core, or the same socket, or any free cpu.
//AffinityLock writerLock = readerLock.acquireLock(SAME_CORE, SAME_SOCKET, ANY);
//new Thread(new SleepRunnable(writerLock, false), "writer").start();
Thread.sleep(200);
} finally {
al.release();
}
// allocate a whole core to the engine so it doesn't have to compete for resources.
//al = AffinityLock.acquireCore(false);
//new Thread(new SleepRunnable(al, true), "engine").start();
Thread.sleep(200);
System.out.println("\nThe assignment of CPUs is\n" + AffinityLock.dumpLocks());
}
static class SleepRunnable implements Runnable {
private final AffinityLock affinityLock;
private final boolean wholeCore;
SleepRunnable(AffinityLock affinityLock, boolean wholeCore) {
this.affinityLock = affinityLock;
this.wholeCore = wholeCore;
}
public void run() {
affinityLock.bind(wholeCore);
int threadId = AffinitySupport.getThreadId();
System.out.println("threadId of one SleepRunnable "+ threadId);
// current cpu bitmap
BitSet currentAffinity = Affinity.getAffinity();
// print the bitmap
StringBuilder s = new StringBuilder();
for( int i = 0; i < currentAffinity.length(); i++ )
{
s.append( currentAffinity.get( i ) == true ? 1: 0 );
}
System.out.println( s );
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} finally {
affinityLock.release();
}
}
}
} |
I try to set affinity to one thread, however,
I get some errors about data type.
The code
The text was updated successfully, but these errors were encountered: