Author Topic: Linux / Android OS operation  (Read 2649 times)

0 Members and 1 Guest are viewing this topic.

Offline phred01Topic starter

  • Contributor
  • Posts: 35
  • Country: au
Linux / Android OS operation
« on: May 08, 2023, 12:53:02 am »
Hi all
Haven't done much programming since retirement 20 yrs ago so out of touch with the world of Linux / Android. Tried to find an appropriate SIG group here in OZ but haven't found one. So I have a number of questions
All linux OS are they compiled to machine code ie binary?
The CPUs used do they have the same instruction sets?
In the old days writing machine code on a 10mhz CPU was struggle to get speed performance in multitasking
With CPUs speed above 1GHZ programs should really fly I have a suspicion all they programs are executed via a line interpreter which is like interpreter BASIC which was so so slow
Would appreciate help in my understanding thanks in advance
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12494
  • Country: us
    • Personal site
Re: Linux / Android OS operation
« Reply #1 on: May 08, 2023, 01:09:22 am »
It depends. On Linux you usually compile to binary. On Android, you generally don't have a lot of control over the underlying OS, you write in Java/Kotlin and it compiles to whatever google wants. It is possible to use binary files, but it is more of an exception when performance is absolutely required.  This is not used by regular apps, it is mostly for high-end games and stuff like that.

There is no basic-like interpreters in modern languages. Even scripting languages like Python first compile into a VM bytecode, which is either executed directly or JIT compiled into machine code.
« Last Edit: May 08, 2023, 01:10:57 am by ataradov »
Alex
 
The following users thanked this post: phred01

Offline retiredfeline

  • Frequent Contributor
  • **
  • Posts: 572
  • Country: au
Re: Linux / Android OS operation
« Reply #2 on: May 08, 2023, 02:04:27 am »
Linux runs on a large number of CPUs with different instruction sets.
 
The following users thanked this post: phred01

Offline Foxxz

  • Regular Contributor
  • *
  • Posts: 139
  • Country: us
Re: Linux / Android OS operation
« Reply #3 on: May 08, 2023, 04:56:53 am »
In linux you have your choice of languages that can be either interpreted or compiled.

Linux runs on a multitude of different CPU architectures with their own OP codes. If you used a compiled language such as C, C++, or Rust you would need to compile the program for each CPU architecture. As long as you've not included anything in your code that depends on a specific CPU type, such as including assembly, then compiling it for multiple architectures shouldn't be much of a problem.

The interpreted languages include Perl, Python, PHP, and a plethora of shell scripting languages. Like BASIC, you don't need to compile your program at all and the interpreter will take care of things as its already been compiled for the CPU architecture. Generally, interpreted languages are slower but that may not be an issue depending on your use-case.

Android programs are generally written in Java because the underlying CPU architecture varies. Java has a runtime environment which shares many similarities to an interpreted language. It can be byte-compiled which is more or less a fancy way of turning source code text into a binary interpreted format.

Hope that helps.
« Last Edit: May 08, 2023, 05:00:16 am by Foxxz »
 
The following users thanked this post: phred01

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 10089
  • Country: us
Re: Linux / Android OS operation
« Reply #4 on: May 08, 2023, 01:24:28 pm »
The Raspberry Pi is a nice way to experiment with Linux on a uC.  For most daily use, the uC solution to replacing a full blown work station is entirely adequate.

I'm kind of fond of the Pi 400 https://www.amazon.com/Raspberry-400-Computer-Kit-RPI400-US/dp/B08MYVQW1S  All you need to add is a mouse and monitor.

Or any of the Pi 4 variants with as much RAM as possible (8 GB?)
https://www.amazon.com/s?k=raspberry+pi+4

gcc, the GNU C compiler does indeed compile to machine code.  App speed is reduced by OS overhead but it's still pretty quick.

As an alternative, Linux will run on just about any PC you have laying around and you can try it with the distribution image before you actually install it to the hard drive.  If you try this 'Live DVD' approach using an actual DVD, bring something to read, it will be pretty grim.  It will run much faster when actually installed.  Linux is a good way to get additional life out of otherwise obsolete PCs.
 
The following users thanked this post: phred01

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 8349
  • Country: fi
    • My home page and email address
Re: Linux / Android OS operation
« Reply #5 on: May 08, 2023, 05:54:32 pm »
All linux OS are they compiled to machine code ie binary?
The kernel, libraries, and OS services are compiled to machine code.

There are support scripts, and some helper utilities and simple applications that use interpreted languages.

Most Android applications, however, are bytecode: see Android Runtime.

The CPUs used do they have the same instruction sets?
No, not at all.

We do use the exact same source code for all architectures, but that source code does have architecture-specific quirks.
If you write a program in C or C++ for Linux, you will be able to compile it to any hardware/CPU architecture machine code Linux supports, and run it (in Linux using that hardware).

If you think about it, that is really neat.  Particularly when one realizes how different some of the architectures are in their details.  (The one I like to point out is hardware locking primitives: both load-linked store-conditional (LL/SC) and compare-exchange (CMPXCHG) -type architectures are supported in Linux, so that code using futexes or pthread mutexes will behave the same on both types of architectures.)

In the old days writing machine code on a 10MHz CPU was struggle to get speed performance in multitasking
With CPUs speed above 1GHz programs should really fly I have a suspicion all they programs are executed via a line interpreter which is like interpreter BASIC which was so so slow
No, it is just that current programmers are very lazy, and prefer to waste CPU and memory resources if it makes their programming job a tiny bit easier.

You can verify this for yourself when you start doing intensive math.  For example, even though the machine I'm writing this post on is over five years old, it only takes seconds to loop over all 32-bit integers, one by one.  Some of my own brute-force mathy stuff verifies (a formula) for all possible finite single-precision floating-point numbers, just to make sure.

When you use Linux and move from traditional spinny disks to good NVMe SSDs, you also realize how much time is taken by just loading stuff from storage to memory.  (I personally am looking forward to getting two same NVMe SSDs to run in software RAID-0, or "striping" mode, up to doubling the data rate.)
 _ _ _ _ _

Note that Linux is not used only on desktops and laptops, and Android on phones.  Both are extensively used in all sorts of appliances, from routers (very often Linux) to TVs (often dedicated variants of Linux or Android) and everything in between.  And on most web servers, including this one.  Hell, over 50% of Microsoft Azure compute cores run Linux, according to Microsoft.

Linux is one of those things that people don't notice, because it is so ubiquitous, and tends to just work.  (That said, on the cheaper end, like in routers, the systems integration work I have seen is laughably atrocious -- literally looks like highschoolers' hobby work.)
(Before you point out that even this forum has had many issues, those tend to be either the forum software or database-related, and not "Linux" issues at all.)

Very often the annoying issues humans see in computer and appliance operation is not actually about speed, but about latency.  For example, my laptop takes about half a minute to boot up from a cold start.  25 seconds or so of that is EFI BIOS, i.e. the computer firmware checking things out, enabling internal buses and waiting for them to stabilise, and so on.  The actual Linux OS takes only about 5 seconds for me to start up –– and unlike Windows, it is actually immediately usable after that, having started up everything, instead of still starting things up in the background.  (This one has a 512 GB Samsung PM961 NVMe SSD, which is pretty darned good, though, even being over five years old.)

Similarly, for example digital TV channel switching is sloooow, because the image cannot be displayed until a P-frame is received.  (To simplify, P-frames describe the entire displayed image, whereas most frames are I-frames, which describe changes to the previous (or next, depending on format) P-frame, typically using motion vectors for small rectangular chunks.)  The channel change latency is due to the technology, and cannot be shortened except when the receiver can "secretly" monitor the data sequences for the other channels.  It is not a programming issue at all.

With graphical user interfaces, the "bling" consumes a surprising amount of resources.  You can see this when comparing e.g. Gnome or KDE desktops to more lightweight (but less visually "bling-y") desktops like LXDE or XFCE.  For pure computing boxes, eschewing display altogether and using remote consoles via e.g. SSH makes a big difference, also explaining why basically all of the 500 most powerful computing clusters in the entire world all run Linux.

 _ _ _ _ _

I personally don't touch Raspberry Pis because of Broadcom and their attitude towards Linux, and would suggest e.g. Odroid-C4 or Odroid-M1 instead.  They are both faster and use less power than 'Pi-4, but are also a bit more expensive.

Those who only interface to Linux stuff via the Raspberry Pi community seem to be quite happy with Pis, though.

In any case, the storage medium you use with such SBCs will affect the experience a lot.  With Odroid-C4, I recommend getting one of the C4-compatible eMMC modules (or at minimum a USB3-connected SSD with just boot on SD-card), and with Odroid-M1, a PCIe 3.0 NVMe M.2 SSD (max. 1600 MB/s) (can also be used as boot media, because Petitboot is on SPI flash on the board).
 _ _ _ _ _

Apologies for the wall of text.  I can't help it, me overly verbose.
 

Offline phred01Topic starter

  • Contributor
  • Posts: 35
  • Country: au
Re: Linux / Android OS operation
« Reply #6 on: May 09, 2023, 10:18:35 am »
Thankx for the education it is obviously been out of the loop for 20 yrs Did notice that that there are Microsoft OS like win 95 and windows 11 have been ported to Pi. Is there emulation kernel being used to achieve this?
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12494
  • Country: us
    • Personal site
Re: Linux / Android OS operation
« Reply #7 on: May 09, 2023, 03:29:30 pm »
Did notice that that there are Microsoft OS like win 95 and windows 11 have been ported to Pi. Is there emulation kernel being used to achieve this?
Win95 is typically set up in a DosBox DOS emulator. The same way as you can run Win95 on any other version of Windows or Linux.

For Win11 they are using ARM versions of the OS provided by Microsoft. They are not the same as x64 versions. And for Win10 they had some dedicated IoT version, which I think was directly supported on RPi, so no additional hacking was required.
Alex
 

Offline barshatriplee

  • Regular Contributor
  • *
  • !
  • Posts: 130
  • Country: bd
Re: Linux / Android OS operation
« Reply #8 on: May 09, 2023, 05:46:25 pm »
1.All Linux operating systems are compiled to machine code, which is also known as binary code. When you write a program in a high-level language like C or Python, it needs to be compiled into machine code so that the computer can execute it. Linux is no exception to this rule.

2. Not all CPUs used in Linux have the same instruction sets. Different CPUs have different architectures and instruction sets, which means that programs compiled for one CPU may not run on another CPU. However, most Linux distributions come with a kernel that supports a wide range of CPUs, so you can generally find a version of Linux that will run on your CPU.

3. In the old days, writing machine code on a 10MHz CPU was a struggle to get speed performance in multitasking. With CPUs speeds above 1GHz, programs should really fly. I have a suspicion that all the programs are executed via a line interpreter, which is like interpreted BASIC, which was so slow.
It's true that modern CPUs are much faster than CPUs from 20 years ago, but that doesn't mean that all programs run faster now. Some programs are still slower than others, depending on how they are written and what they are doing. Additionally, not all programs are executed via a line interpreter. Some programs are compiled directly into machine code, which means they run much faster than interpreted programs. However, some interpreted programs, like Python or Perl scripts, can still run quite fast, especially if they are well-written and optimized.
 

Offline phred01Topic starter

  • Contributor
  • Posts: 35
  • Country: au
Re: Linux / Android OS operation
« Reply #9 on: May 13, 2023, 12:31:18 pm »
My interest has been kindled by looking at Android head units. Wanting to run the latest apps found to my horror that the Chinese units are running fake Android OS like 11 /12 This is what I found Single core 1G ram 16G flash claims to be Android 6.1 but a disguised Android 4.4.  4 core units claim to be 10/11/12 these can be  Android  6 or at best Android 8.1 On 8 core units claiming 11/12 are Android 10. I would like to upgrade some 4 core units to at least Android 10 Tried to locate basic binary code to build a specific version with the required drivers. Is it possible to extract drivers from the fake android OS and then add them to a generic Android 10? Just like installing the latest generic windows on a PC platform
 

Offline phred01Topic starter

  • Contributor
  • Posts: 35
  • Country: au
Re: Linux / Android OS operation
« Reply #10 on: May 13, 2023, 12:35:27 pm »
Yes tried this loaded Android on a Pi 400 but found that some of the latest apps fail to install. Haven't been able to run XAPKs as yet
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

-->