What RaspberryPi lack is a battery backed RTC (Real Time Clock). It's device that can work independently from main computer and keep track of a passing time even when it's off (this is why it has its own battery). It may work in very simple way - it has a known frequency oscillator connected and on every pulse of the oscillator, it will increment its internal timer/counter. Since the frequency is know, it's easy to calculate the time passed based on the counter. The device will also have a battery so that it can continue working even when external power is off.
Some RTC devices may be more sophisticated. They can, for example, create an interrupt in programmable frequency or in alarm mode (set to a certain time in the future or to certain time each day etc). It is not relevant to keeping system time and is optional.
How RTC is used
A computer can ask RTC what time it is (or more precisely - what is its counter value) at boot time and set its internal date/time based on this value. From now on, however, a computer won't ask RTC for time every second/milisecond/microsecond. Instead, it will run its own clock (called system time), usually using its own timers/counters. Just like in RTC, timer/counter is clocked with a known frequency so it's easy to calculate the time passed.
You may force your system to synchronize its clock with RTC device (in both directions) but it won't happen until requested. Some systems are configured to store system time in RTC when shutting down or after NTP synchronization, for example.
Lack of RTC
RaspberryPi, like many cheap single board computers, does not have external RTC device. This means that it can't ask for current time on boot. But as already mentioned - this is not a problem if we can get date/time from other source (like NTP). The only disadvantage is that unlike RTC, you can't ask NTP on early boot (since you first need network connection).
So to directly answer your question - no matter if RaspberryPi (or any other computer) has RTC or not, it will keep track of time using internal timer/counter device which is available in almost every computer system and is required to run almost any kind of operating system.
Time in Linux
Userspace applications in Linux can determinate so called
calendar time (which is a time in real world) using
gettimeofday() function which then calls
clock_gettime() system call. What happens now is a little bit complicated due to many advanced features that Linux kernel has (like namespaces etc). But the basics is that kernel maintains its time based on
jiffies. Its actually just a variable inside of the kernel (usually 64bit wide) that counting number of ticks since the system started.
Ticks are generated by hardware timer by means of
jiffies value is incremented on each such interrupt. Hardware timer is configured to produce such interrupts at regular intervals. The interval is configured at boot time according to a value of
HZ kernel config parameter.
At any given time, kernel knows how many ticks where generated from boot (
jiffies variable), it knows how many such ticks are generated each second (
HZ config option) so it can easily calculate how much time passed from the last boot.
So to sum up - kernel asks
calendar time (also called
wall clock) on boot so it knows what was the actual time when system started. It then adds
jiffies/HZ value to this each time a userspace application asks what time it is using
clock_gettime system call.
Hardware timer/counter device
Hardware timer/counter is a very simple device. It has a counter register that counts its clock ticks. Clock ticks are usually created by some external
oscillator (an electronic circuit that produces repetitive signal) and are of known frequency (usually ranging from couple of kHz to hundreds MHz). This means that we can easily calculate how much time passed by dividing the counter value by the frequency of oscillator.
Timer device can be programmed to do various things - it can count upwards and downwards, compare counter register to some value. For example it can create an external signal and start counting from beginning when counter register is at some value. This way you can configure timer device to create such external signal at constant interval that is much lower frequency than oscillator. This signal can be then used as an interrupt event for a CPU.
Note that oscillator could be used directly instead of timer device. What differentiates timer/counter device from oscillator is that it can be programmed. So you can think of timer/counter device as a much more sophisticated oscillator.