Sunday 28 March 2021

Laptop Hardware Update

A long time ago I used to have some good knowledge about computer hardware, but that's no longer the case. In the last years I only get slightly updated about hardware evolution when I buy (or receive from my employer) a new laptop. This has been the case recently, and out of curiosity I've been learning a few things.

Unless you're a gamer or 3D guy and has bought a laptop accordingly to you extra needs, it's 99% likely that your laptop has an integrated GPU, and not a dedicated one in a separate chip in the motherboard. Well, indeed, we could say that there are 2 different levels of GPU integration.

  • What we properly call integrated GPU means that a CPU die and a GPU die (a die is a block of semiconducting material) are placed in the same processor package.
  • AMD evolved this schema to what is called an APU, where the CPU and GPU are built on the same die. Notice that both entities continue to exist, it's not that the GPU has disappeared and the CPU is taking over its work.

I remember from the old times the existence of 2 main chips on the motherboard, the Northbridge and the Southbride. The Northbridge mainly takes care of the communication between CPU, GPU and Memory. My understanding is that in an integrated GPU the Nortbridge circuit (or a circuit with most of the functionality that was present in the traditional Northbridge) is also placed in the processor package but as a separate die. In an APU the Northbridge is built on the same die as CPU and GPU.

Integrated GPU's and APU's (I'll just use the term "integrated" for both cases), do not have a separate graphic memory, but they use the normal RAM for their tasks. Anyway, we'll continue to hear about the dedicated graphic memory of our integrated GPU. In this case, "dedicated" means that one fixed portion of the normal RAM is permanently reserved for graphic use, and is no longer available to the CPU. Apart from that, we have the shared GPU memory, that is the amount of normal RAM that can be shared between CPU and GPU, and that normally is set to 1/2 of the remaining physical memory. Portions of this shared GPU memory is taken and released by the GPU as needed, and if we are not using games or 3D stuff chances are that the GPU has enough with just the dedicated memory.

One could wonder why that dedicated memory is needed. In in many occasions we will be using just one part of it, so taking away all of it from the CPU beforehand seems odd... Well, it seems there are performance considerations. This dedicated memory is contiguous memory so its use will be a bit faster. Additionally, when reserving graphic memory from the shared memory there is additional logic to "negotiate" this. It's mentioned here.

I suspect the 2GB reservation is a firmware bug. 2GB is quite aggressive on an 8GB system and unlikely to have much higher graphics performance than say a 256-512MB up-front contiguous reservation with the rest being on-the-fly allocated "shared" memory. With modern hardware, the latency penalty for on-the-fly shared memory allocations and the associated scatter/gather techniques to collate them is small except for very specific workloads.

Windows 10 is quite good showing information about Graphic memory. In my work laptop I have 16 GBs of RAM, of which 512 MBs are dedicated to graphic use, and almost 1/2 of the remaining memory is availabe as shared graphic memory.

We can also see information in the Memory tab:

There's still something that I don't fully understand. As you see above, it says that 792 MBs are Hardware reserved. As we've seen in the first screenshot, 512 MBs are reserved (dedicated) for the GPU, so we have a 280 MBs gap!. OK, we should know that because of Memory-mapped I/O. Memory-mapped I/O remained confusing to me for years until I read this excellent answer. So part of the physical address space is used for accessing to IO devices rather than for RAM access. In 32 bits systems, where the address space is limited to 4 GBs that means that the CPU won't be able to use more than around 3.5 GBs of RAM. However, in 64 this is not a problem. As we have a huge address space, the addresses reserved for IO should be well above the addresses of our physical memory.
Well, given this 280 MBs gap in my system (I see something similar in my personal laptop too), maybe for some reason one part of the Memory-mapped I/O address space needs to be taken from the lower address space!?

Sunday 21 March 2021

Async Calls and Fluent Interface

I guess almost everyone will agree in what an improvement the addition of the async/await syntax sugar to JavaScript and C# has meant for asynchronous programming. We know that the compiler will generate code using the then/ContinueWith methods (I've already linked this beautiful article years ago), but for the most part we can forget about the callback style that comes with these methods and enjoy the much cleaner "synchronous like" style allowed by async/await.

This said, there are still a few occasions when calling then ourselves will make our code cleaner than using async/await. I've come across one case recently and I'm going to share it here.

Let's say we have a fluent interface where some (or all) of the methods are asynchronous. For example, one class like this:


class DbHelper{
    addConnectionString(conSt){
        console.log("adding connection string");
        this.connectionString = conSt;
        return this;
    }

    encryptConnectionStringAsync(){
        console.log("encrypting connection string");
        this.connectionString = "XYXYXYXYX";
        return new Promise((resFn, rejFn) => setTimeout(() => resFn(this), 2000));
    }

    openConnectionAsync(){
        console.log("opening connection string");
        this.connection = {};
        return new Promise((resFn, rejFn) => setTimeout(() => resFn(this), 2000));
    }

    cacheBasicDataAsync(){
        console.log("caching basic data");
        this.dataCache = {};
        return new Promise((resFn, rejFn) => setTimeout(() => resFn(this), 2000));
    }

    runQuery(query){
        console.log("running query");
        return "query result";
    }

    runQueryAsync(){
        console.log("running async query");
        return new Promise((resFn, rejFn) => setTimeout(() => resFn("query result"), 2000));
    }
}

A chain of calls in this fluent class using await looks a bit confusing I would say:


let dbHelper = new DbHelper();

dbHelper = await (
	(await 
	    (await dbHelper.addConnectionString("conSt")
		.encryptConnectionStringAsync()
	    ).openConnectionAsync()
	).cacheBasicDataAsync()
);

let res = await dbHelper.runQueryAsync();
console.log("result: " + res);

However, using then to chain the calls looks much clearer in this case:


let dbHelper = new DbHelper();

dbHelper = await dbHelper.addConnectionString("conSt")
    .encryptConnectionStringAsync()
    .then(dbH => dbH.openConnectionAsync())
    .then(dbH => dbH.cacheBasicDataAsync());

let res = await dbHelper.runQueryAsync();
console.log("result: " + res);

Friday 19 March 2021

Windows Power States

I've recently received a new laptop from my employer, a pretty nice Lenovo machine. After the first days using it I realised there was something odd. When waking it up in the morning after having put it to sleep in the late evening, the battery level had quite dropped, one day the laptop was hot as if it had not really entered into sleep. I suspended it several times and it seemed to get into sleep OK, so maybe it was more a thing of waking up from the suspended state for some reason. The windows event log seemed to show it entering into suspension and going mute, but after several hours there would be entries in the log, so yes, something was waking it up.

Doing some searches for Windows 10 Sleep/Stand by issues I thought I've found what was happening. Windows 10 comes with a new Sleep mode, Modern Standby (S0 Low-power Idle) that, if your hardware supports it, is used rather than the previous S3 mode (my previous Lenovo work laptop, dating back to 2017 did not support Modern standby). This Modern Standby thing comes with 2 modes: Connected and Disconnected.

Devices that support Modern Standby can connect or disconnect from Wi-Fi or a wireless local area network while in standby.

- Connected Modern Standby will allow the device to remain connected to Wi-Fi while in standby. It will be able to receive and process notifications about new email messages, incoming calls. This is convenient, but makes the device drain the battery power faster.
- Disconnected Modern Standby allows longer battery life, but the device won't notify you about new events.

Resuming from "traditional" sleep mode has always been almost immediate, so for most users I don't see what's the use of Connected Modern Standby mode in a laptop. Receiving notifications while it's in standby and hence waking up?! I guess after that it will go back to sleep following the inactivity rules on your system, but if you're receiving notifications pretty often this will be a battery draining mess. I was thinking it could be something like that what was happening to my laptop, so I wanted to turn off this behaviour.

First I confirmed with powercfg -a that my new laptop is using this Connected Modern Standby thing.

As you can see, the traditional S3 mode is not supported by my Hardware. It seems Hardware can not support both Sleep states (read here

Modern Standby is only available on some SoC systems. When it's supported, the system does not support S1-S3.

So the solution is switching from Connected Modern Standby to Disonnected Modern Standby. For that you just have to go to Settings -> System -> Power & Sleep and in the Network connection settions select Always

Unfortunately I've faced once again the problem of finding my laptop hot and with a very low battery level in the morning, even when using this Disconnected mode... Checking the event log it seems the laptop got into sleep and woke up immediatelly, don't know why, so I've had to resort so far to the Hibernate mode to avoid problems. Anyway, it's been interesting to learn about the current types of Power States in modern Windows/modern Hardware.

Sunday 7 March 2021

What People Will Say

I watched last night an excellent Norwegian film What People Will Say (this title summarizes pretty well the story, while the Spanish choice, "El Viaje de Nisha", is quite more abstract). I think this is my second Norwegian film, the first one had been Thelma, also an excellent one.

What People Wil Say tells the story of a Norwegian teenage girl born in a Muslim family of Pakistani immigrants. She's a happy Western teenager, that has fun with her other Norwegian friends that follow different scales of melanin (from a pale, red haired "Viking" to one girl of african descent). Then, a conflict with her conservative family breaks out and they end up sending her to Pakistan to live with some relatives so that she can be educated in "good, proper values", and not in the "absurd" moral of the Westerns (as her parents say). The story goes on, but it's up to you to fully discover and enjoy it.

There's beauty in the beginning of this film, a beauty that still seems familiar to me, but that having lived in France in recent times (and following day by day the involution of French-Belgian-German... societies) also seems so far away. The beauty of seeing how the second generation of immigrants, those born in our soil and granted with all the rights that this involves, try to live a normal life, try to be one more of us, try to enjoy the freedoms and opportunities that European civilization gives us. I guess a story like this is possible in Norway (or for example in Spain) because there immigration of distant cultures is relatively recent, and they are now in the second generation. Unfortunately a story like this is no longer possible in countries that are SUFFERING now the third of fourth generation of Muslim immigrants. That generation that no longer wants to be one of us, that no longer want to enjoy our freedoms, but on the contrary want to cut back others freedoms imposing on the rest of the population their medieval codes and morals.

I know that there is no soft solution for France, Belgium... Demography plays against freedom... For the moment we'll continue to see the "Libanization" of our countries, and then it will end up either in a civilizational war between Normal Europeans, Asians, South Americans and a few very moderate Muslims on one side, and Muslims and Far Left degenerates on the other side... or in the total submission and conversion of Non Muslims to Islam.

I hope in Norway it can be different. If they learn from the errors of other European countries and they silence (destroy) the Far Left and expel all Muslims not adhering to a very moderate interpretation of their religion (or any other group that permanently complains about the "evil" Europeans) then they can have a beautiful society. A mixed society where your skin-eyes-hair color, the straighten of your hair, or the birthplace of your parents represents nothing... That's a beautiness that countries like France enjoyed for a few decades, before the religious, decolonial, indigenist... madness ruined it all...

"Cerise sur le gâteau" (icing on the cake), the director, Iram Haq is a Norwegian of Pakistani descent, and this film is inspired by her own life experience. One can say for sure that she's "une chance pour l'Europe", someone that has given to our society as much or more than our society has given to her... quite different from Daniele Obono, Rhokia Dhialo, Camelia Jordana, the Traoré family-gang... and so many imported scumbags that rot our existence...

There's an important passage in the story that I should mention. While in Pakistan, she and his boyfriend are caught kissing each other by 3 corrupt policemen that beats them and force her to take off her clothes while filming her. Then they blackmail the family or otherwise they'll publish the video on the internet. It's amazing, a country ruled by medieval moral rules that leverages modernity to make things even worse... well, nothing new, Pakistan is a Nuclear Power...

Saturday 6 March 2021

Zemmour et l'Algerie

We, humans, are complex, very complex (at least some of us). Each individual has millions of variables that play a role in his behaviour. The environment where you are born and raised play a tremendous role in what you become, but hopefully we are much more complex than that. We have internal configurations that can make us see elements invisible to those that surround us, or just the contrary. It's because of this that I try to start from scratch when I first deal with someone, discard the "generic" information, like nationality, age, the way he looks... This said, when you have to approach a whole bunch of people (like for example when thinking whether a place would be a good one to live, to set up a business, to allow them to join an organization, to welcome its citizens into our own land, or just to pay a visit...), we need to use generalizations. Do an average of all the complexities of the individuals living in that place to get a simplified, but necessary, view.

That said, I can say that I profundly distate Turkey and Algeria, 2 of the most backward, ultranationalist, xenophobic, illiterate (at least for anything related to a basic knowledge of history) and full of hate societies in the world. Being an European I'm more than entitled to hate dislike Turkey as a country, our eternal enemy, the eternal enemy of Western civilization. Being a Francophile (Je peux dire que je suis un "Francais de coeur") I have every right to hate dislike Algeria. It's a response to all the hatred that most of them profess us (both to the French nation and to the French people), a response to all their ungratefulness after all what France has done for them, both for the Algerian territory and for the Algerians (and their damned descendants) that unfortunately (for most cases) have immigrated to France. A response to all the French people murdered by Algerians both during the French colonial period and particularly during their migratory invasion of the French soil. To all the French girls raped by maghrebian criminals (sexual violence prompted not just by their primitive approach to sexuality, but by their hatred towards non-muslims, particularly French non-muslims). To all the French people attacked with pure "racial" hatred by Algerian criminals just because of an alleged "mauvais regard/bad look". To all the supermarket cashiers having to "enjoy" a "sale blanc-blanche, sale Francais / fucking white, fucking French" compliment day after day from some "lovely" customers... A response to every time we've had to hear a "nique la France/Fuck France" from one of these ungrateful beasts...

I'm not going to give a History lesson here, it's not my role. I won't say that everything that was done during the French colonial period (I would prefer to call it civilizing mission) in Algeria was perfect, sure it was not, humans make mistakes, so for sure there were misbehaviours (mainly during the first decades), but all in all, French colonization is the best thing that has ever happened to that territory known today (I remark that as Algeria as such did not exist before the French arrived there) as Algeria. The rejection of this fact clearly shows how ignorant and brainwashed many Algerians (and their friends from the French Radical Left) are.

After these 3 introductory paragraphs, I can go to the point of this post, pasting here several priceless reflections about Algeria from the almighty Eric Zemmour. If you don't know who Eric Zemmour is, you should at least read this. I'll just say that he's the most important French journalist-historian of this century, born in Paris in 1958 to Algerian Jews.

You can find the original texts here

L'#Algérie a toujours été colonisée. Mais elle ne se plaint que de la colonisation Française. Pas de la colonisation arabe, turque, espagnole... qui n'ont rien laissées. On ne se plaint que de la France, alors que la France a tout apporté à l'Algérie...

Algeria has always been under colonial rule. But they only complain about the French colonization. They do not complain about the Arab, Turkish, Spanish... one, that did not leave anything. They only complain about France, while France has given everything to Algeria.

En #Algérie, depuis 60 ans, le régime du #FLN a été une castastrophe... L'Algérie achète tout à l'extérieur et ne vit que sur le pétrole. Et qui a découvert le pétrole ? L'affreux colonisateur Français. Et l'Algérie doit tout aux ingénieurs Français

In Algeria, for 60 years, the FLN regime has been a catastrophe... Algeria has to buy everything abroad and has no other income than oil. And, who did find oil? The evil French colonizer. Algeria owes everything to French engineers.

l'Algérie doit tout a la France. Ils n'ont absolument rien à part le pétrole, qui a été découvert grâce aux ingénieurs français. Ils n'ont aucunes autres ressources et importent absolument tout. C'est les islamistes qui gouvernent maintenant

Algeria owes everything to France. They have nothing at all other than oil, found by French engineers. They have no other resources and they import absolutely everything. Nowadays it's the Islamists who are in charge.